How can I store the messages which I've written through javamail into MySQL table? I've already configured james server config file to connect to MySQL server(with datasource element name maildb), and I changed the <inboxRepository>
element in James server config file to
如何将我通过javamail编写的消息存储到MySQL表中?我已经配置了james服务器配置文件来连接MySQL服务器(数据源元素名为maildb),我将James服务器配置文件中的
<inboxRepository>
<repository destinationURL="db://maildb/spammer/"
type="MAIL"/>
</inboxRepository>
But I'm still not able to read the messages from the inboxes column of table spammer table in the mail database in MySql.
但我仍然无法从MySql中的邮件数据库中的垃圾邮件发送者表的收件箱列中读取邮件。
Here's my javamail class:
这是我的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();
}
}
}
}
What am I doing wrong here, and how can I read the message from spammer table in MySQL?
我在这里做错了什么,如何从MySQL中的垃圾邮件表中读取消息?
1 个解决方案
#1
1
Maybe you using wrong URL to database: destinationURL="db://maildb/spammer/" I propose change to destinationURL="mysql://maildb/spammer/" if destination is mysql database of course.
也许您使用错误的URL到数据库:destinationURL =“db:// maildb / spammer /”我建议更改到destinationURL =“mysql:// maildb / spammer /”如果destination当然是mysql数据库。
#1
1
Maybe you using wrong URL to database: destinationURL="db://maildb/spammer/" I propose change to destinationURL="mysql://maildb/spammer/" if destination is mysql database of course.
也许您使用错误的URL到数据库:destinationURL =“db:// maildb / spammer /”我建议更改到destinationURL =“mysql:// maildb / spammer /”如果destination当然是mysql数据库。