8

如何将通过 javamail 写入的消息存储到 MySQL 表中?我已经将 james 服务器配置文件配置为连接到 MySQL 服务器(数据源元素名称为 maildb),并且我将<inboxRepository>James 服务器配置文件中的元素更改为

<inboxRepository>
  <repository destinationURL="db://maildb/spammer/"
    type="MAIL"/>      
</inboxRepository>

但是我仍然无法从 MySql 的邮件数据库中的垃圾邮件发送者表的收件箱列中读取消息。

这是我的 javamail 类:

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class mail{

  public static void main(String[] argts){
    String to = "red@localhost";
    String from = "blue@localhost";
    String subject = "jdk";
    String body = "Down to wind";

    if ((from != null) && (to != null) 
      && (subject != null)  && (body != null)) 
    // we have mail to send
    {
      try {
        Properties props = new Properties();

        props.put("mail.host", "127.0.0.1 ");
        props.put("mail.smtp.auth","true");

        Session session = 
          Session.getInstance(props, new javax.mail.Authenticator() {

          protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("blue", "blue");
          }
        });
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        Address[] add={ new InternetAddress(to) };
        message.setRecipients(Message.RecipientType.TO,add);
        message.setSubject(subject);
        message.setContent(body, "text/plain");
        message.setText(body);
        Transport.send(message);

        System.out.println
          ("<b>Thank you. Your message to "+to+" was successfully sent.</b>");

      } catch (Throwable t) {
        t.printStackTrace();
      }
    }
  }
}

我在这里做错了什么,如何从 MySQL 中的垃圾邮件发送者表中读取消息?

4

1 回答 1

1

也许你使用了错误的 URL 到数据库:destinationURL="db://maildb/spammer/" 如果目的地当然是 mysql 数据库,我建议更改为 destinationURL="mysql://maildb/spammer/"。

于 2011-07-13T12:32:27.077 回答