我在带有 JDK 7_10 和 GAE Maven 插件的 Mac OS X 上使用 GAE API 1.7.3。
我的测试或多或少是从文档中复制的:
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”是空的,但“Data length”是5(对应于“.....”)。
这是正常的还是我在这里做错了什么?
[更新]如果我使用低级 API,也是一样的:
MailService service = MailServiceFactory.getMailService();
service.send(new MailService.Message(from, to, subject, text));