Reputation: 3
I am planning to use Google App Engine to deploy a web application. 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?
Upvotes: 0
Views: 213
Reputation: 21835
Yes you can use JavaMail to Send Mail. 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("[email protected]", "Example.com Admin"));
msg.addRecipient(Message.RecipientType.TO,
new InternetAddress("[email protected]", "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:
Upvotes: 1