如何将通过 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 中的垃圾邮件发送者表中读取消息?