Sending Email Messages
by , 04-25-2012 at 09:28 PM (657 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;
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.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@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) { // ... }









Email Blog Entry
Size Reduced for Images in PDF &...
05-15-2013, 05:53 PM in Java Software