Show TOC Start of Content Area

Procedure documentation Creating E-Mail Messages  Locate the document in its SAP Library structure

Use

E-mail messages are represented by javax.mail.internet.MimeMessage objects. A MimeMessage object represents a Multipurpose Internet Mail Extensions (MIME) format message. It can have a header, footer, body, attachments, recipients and other attributes. They are represented by the corresponding classes in the Java Mail API.

You can add content to the message by using the corresponding methods in the message objects. For example:

      setSubject – Sets the subject of the message

      setContent – Sets the content of the message

      setRecipients – Sets the recipients’ addresses, implementing the TO type of recipients that is defined by the javax.mail.Message.RecipientType.

      addFrom – Adds the addresses to the existing "From" attribute.

The InternetAddress class represents the e-mail address.

Procedure

...

       1.      Create a new MimeMessage object, passing the session object as an argument to the constructor.

This creates an initially empty message.

       2.      Using the corresponding methods of the message object, add the necessary content to the message.

       3.      Send the message.

More information: Sending E-Mail Messages.

Example

The following example illustrates creating a simple e-mail message.

MimeMessage message = new MimeMessage(ses);

message.setSubject("Test", "UTF-8");

message.setContent("This is test", "text/html;charset=UTF-8");

message.setRecipients(javax.mail.Message.RecipientType.TO, "test1@myHost.my");

InternetAddress[] to = new InternetAddress[]{new InternetAddress("bobby@myHost.my");}

message.addFrom(to);

 

End of Content Area