简体   繁体   English

从Google App Engine发送电子邮件警报

[英]Send Email alerts from Google App Engine

I am planning to use Google App Engine to deploy a web application. 我打算使用Google App Engine部署Web应用程序。 The application sends alerts by email to users if some other users does some activity on the user's page. 如果其他一些用户在用户页面上进行了某些活动,则该应用程序通过电子邮件向用户发送警报。 Is there any way I can send notifications to the user by an email in this case? 在这种情况下,有什么方法可以通过电子邮件向用户发送通知?

Yes you can use JavaMail to Send Mail . 是的,您可以使用JavaMail发送邮件 Here is an example taken from the docs: 这是一个取自文档的示例:

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

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

        String msgBody = "...";

        try {
            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(msgBody);
            Transport.send(msg);

        } catch (AddressException e) {
            // ...
        } catch (MessagingException e) {
            // ...
        }

It is also important that the sender address must be one of the following types: 发件人地址必须是以下类型之一也很重要:

  • The address of a registered administrator for the application 该应用程序的注册管理员地址
  • The address of the user for the current request signed in with a Google Account. 使用Google帐户登录的当前请求的用户地址。 You can determine the current user's email address with the Users API. 您可以使用Users API确定当前用户的电子邮件地址。 The user's account must be a - Gmail account, or be on a domain managed by Google Apps. 该用户的帐户必须是-Gmail帐户,或者位于由Google Apps管理的域上。
  • Any valid email receiving address for the app (such as xxx@APP-ID.appspotmail.com). 该应用程序的任何有效电子邮件接收地址(例如xxx@APP-ID.appspotmail.com)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM