我在Mac OS X上使用带有JDK 7_10和GAE Maven插件的GAE API 1.7.3。
我的测试或多或少地来自the documentation:
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("admin@example.com", "Example.com Admin"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("user@example.com", "Mr. User"));
msg.setSubject("Your Example.com account has been activated");
msg.setText(".....");
Transport.send(msg);
输出结果为:
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: MailService.send
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: From: "Example.com Admin" <admin@example.com>
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: To: "Mr. User" <user@example.com>
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: Reply-to: "Example.com Admin" <admin@example.com>
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: Subject: Your Example.com account has been activated
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: Body:
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: Content-type: text/plain
Dez 21, 2012 12:24:24 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: Data length: 5
使用以下方法初始化单元测试:
protected LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalMailServiceTestConfig());
真正奇怪的是,“Body”是空的,但“数据长度”是5(对应于“.....”)。
这是正常的还是我在这里做错了什么?
[更新] 如果我使用低级API,那就是同样的事情:
MailService service = MailServiceFactory.getMailService();
service.send(new MailService.Message(from, to, subject, text));
答案 0 :(得分:4)
您是否在setLogMailBody(true)
上致电LocalMailServiceTestConfig
?