Question

I was trying a method to implement email notification Using JavaMail.I wrote the code and there is no error. But no email has been sent. I am using GAE with JSF2.

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) {
    // ...
}

Where I went wrong?

Was it helpful?

Solution

Check that 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.

According to the App Engine Mail API documentation:

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top