0

我正在使用谷歌应用引擎的邮件发送电子邮件。贝娄是我的代码

Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);

Message msg = new MimeMessage(session);
try {
msg.setFrom(new InternetAddress(from));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setText(message);
Transport.send(msg);
    } catch (AddressException e) {
        throw new InvalidMailInputException("Invalid email.");
    } catch (MessagingException e) {
        throw new InvalidMailInputException("Unable to send eamil at this time.");
    }

日志:

Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO: MailService.send
Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO:   From: myaddress@gmail.com
Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO:   To: myaddress@gmail.com
Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO:   Reply-to: myaddress@gmail.com
Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO:   Subject: Appoint has been cancelled successfully (5)
Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO:   Body:
Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO:     Content-type: text/plain
Apr 13, 2013 5:26:29 PM com.google.appengine.api.mail.dev.LocalMailService log
INFO:     Data length: 147

在日志消息中,我没有收到任何错误。但是,我也没有收到电子邮件。

感谢您的帮助。

4

1 回答 1

2

看起来您正在使用本地开发服务器。在这种情况下,实际上不会发送任何邮件。

来自: https ://developers.google.com/appengine/docs/java/mail/overview#Development_Server

当开发服务器中运行的应用程序调用邮件服务发送电子邮件消息时,该消息将打印到日志中。Java 开发服务器不发送电子邮件。

于 2013-04-15T09:51:36.147 回答