使用 JavaMail 的电子邮件通知

发布于 2025-01-06 17:18:16 字数 1103 浏览 1 评论 0原文

我正在尝试一种使用JavaMail实现电子邮件通知的方法。我编写了代码,没有错误。但没有发送任何电子邮件。 我将 GAE 与 JSF2 结合使用。

Properties props = new Properties();
javax.mail.Session session1 = javax.mail.Session.getDefaultInstance(props, null);

String msgBody = "This is a test mail";

try {
    System.out.println("Email notification is sending");
    Message msg = new MimeMessage(session1);
    msg.setFrom(new InternetAddress("[email protected]", "Example.com Admin"));
    msg.addRecipient(Message.RecipientType.TO,
            new InternetAddress("[email protected]", "Mr. User"));
    msg.setSubject("Your Example.com account has been activated");
    msg.setText(msgBody);
    Transport.send(msg);
    System.out.println("Email notification has been sent");
} catch (AddressException e) {
    // ...
} catch (MessagingException e) {
    // ...
}

我哪里出错了?

I was trying a method to implement email notification Using JavaMail.I wrote the code and there is no error. But no email has been sent.
I am using GAE with JSF2.

Properties props = new Properties();
javax.mail.Session session1 = javax.mail.Session.getDefaultInstance(props, null);

String msgBody = "This is a test mail";

try {
    System.out.println("Email notification is sending");
    Message msg = new MimeMessage(session1);
    msg.setFrom(new InternetAddress("[email protected]", "Example.com Admin"));
    msg.addRecipient(Message.RecipientType.TO,
            new InternetAddress("[email protected]", "Mr. User"));
    msg.setSubject("Your Example.com account has been activated");
    msg.setText(msgBody);
    Transport.send(msg);
    System.out.println("Email notification has been sent");
} catch (AddressException e) {
    // ...
} catch (MessagingException e) {
    // ...
}

Where I went wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ι不睡觉的鱼゛ 2025-01-13 17:18:16

检查您的发件人电子邮件地址是否注册为应用程序管理员,或者是登录应用程序的当前用户的电子邮件地址。

根据 App Engine Mail API 文档

为了安全起见,消息的发件人地址必须是
应用程序管理员的电子邮件地址
或任何有效的
应用程序的电子邮件接收地址(请参阅接收邮件)。 发件人
也可以是当前用户的 Google 帐户电子邮件地址
已登录
(如果用户的帐户是 Gmail 帐户或位于
由 Google Apps 管理的域。

Check that your sender e-mail address either registered as the administrator of your app, or the e-mail address of the current user that's logged in to the app.

According to the App Engine Mail API documentation:

For security purposes, the sender address of a message must be the
email address of an administrator for the application
or any valid
email receiving address for the app (see Receiving Mail). The sender
can also be the Google Account email address of the current user who
is signed in
, if the user's account is a Gmail account or is on a
domain managed by Google Apps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文