Appendix M.2 Creating messages

Create the message you want to send.

Specify the following content in the message:

An example of setting the message contents is as follows:

MimeMessage msg = new MimeMessage(session);
try{
   // Set up the From header field
   msg.setFrom();

   // Set up the To header field
   msg.setRecipients(MimeMessage.RecipientType.TO, "to_address@example.com");

   // Set up the Subject header field
   msg.setSubject("Message subject", "ISO-2022-JP");

   //Set up the user-defined field
   msg.setHeader("MyHeader", "MySendMailClient");

   // Set up the mail text
   msg.setText("Mail message text", "ISO-2022-JP");

   // Set up the Date header field
   msg.setSentDate(new java.util.Date());

} catch (MessagingException e) {
   // Failed to analyze mail address
}