[英]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: 发件人地址必须是以下类型之一也很重要:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.