Google App Engine を使用して Web アプリケーションをデプロイする予定です。他のユーザーがユーザーのページでなんらかのアクティビティを行った場合、アプリケーションは電子メールでアラートをユーザーに送信します。この場合、メールでユーザーに通知を送信する方法はありますか?
1 に答える
1
はい、 JavaMail を使用してメールを送信できます。ドキュメントから抜粋した例を次に示します。
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) {
// ...
}
また、送信者アドレスが次のいずれかのタイプである必要があることも重要です。
- アプリケーションの登録管理者のアドレス
- Google アカウントでログインしている現在のリクエストのユーザーのアドレス。ユーザー API を使用して、現在のユーザーのメール アドレスを確認できます。ユーザーのアカウントは - Gmail アカウントであるか、Google Apps によって管理されているドメインにある必要があります。
- アプリの有効なメール受信アドレス (xxx@APP-ID.appspotmail.com など)。
于 2013-11-03T23:00:18.640 に答える