Adsense

Thursday, 8 August 2013

Email Notification Using JavaMail - Google App Engine

Code:

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("myGmailId1@gmail.com", "Example.com Admin"));
    msg.addRecipient(Message.RecipientType.TO,
            new InternetAddress("myGmailId2@gmail.com", "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) {
    // ...
}

Note:
 
  • 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.
  • 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.

No comments:

Post a Comment