我打算使用Google App Engine来部署Web应用程序。如果某些其他用户在用户页面上执行某些活动,则应用程序会通过电子邮件向用户发送警报。在这种情况下,有什么方法可以通过电子邮件向用户发送通知吗?
答案 0 :(得分:1)
是的,您可以使用JavaMail to Send Mail。以下是从文档中获取的示例:
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) {
// ...
}
发件人地址必须是以下类型之一也很重要: