View RSS Feed

Java Mail

Sending Email Messages

Rate this Entry
by , 04-25-2012 at 10:28 PM (1510 Views)
A MimeMessage object is prepared by an application so that to send email. Email is sent along with static method send(), on Transport class. JavaMail session object is used to create the message. Transport and session work along with App Engine Mail service, with no extra configuration.

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;
Java Code:
// ...
        Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

        String msgBody = "...";

        try {
            Message msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress("", " Admin"));
                             new InternetAddress("", "Mr. User"));
            msg.setSubject("Your account has been activated");

        } catch (AddressException e) {
            // ...
        } catch (MessagingException e) {
            // ...
Calls which are made to the mail service are basically asynchronous and hence are immediately returned. Recipient mail servers are contacted and messages are delivered by Mail service management. If problem is there to send messages to recipient, error messages will be sent to sender.

Submit "Sending Email Messages" to Facebook Submit "Sending Email Messages" to Digg Submit "Sending Email Messages" to Submit "Sending Email Messages" to StumbleUpon Submit "Sending Email Messages" to Google

Mail Message