Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: send a multipart/mixed message

Java: send a multipart/mixed message

import java.util.Date;
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class JavaMail_Mime
  static String message1 = "Hello, from here";
  static String message2 = "Hello, from there";
  public static void main(String[] args)
    Properties prop = new Properties();
    prop.put("mail.smtp.host", "myMailServer");
    prop.put("mail.from", "me@example.com");
    String to = "contact@exemple.com";
    Session session = Session.getInstance(prop, null);
    try {
      // create message
      MimeMessage msg = new MimeMessage(session);
      // set message header
      msg.setRecipients(Message.RecipientType.TO, to);
      msg.setSubject("multipart/mixed message example");
      msg.setSentDate(new Date());
      // Create body part for 1st and 2nd messages
      MimeBodyPart mbp1 = new MimeBodyPart();
      MimeBodyPart mbp2 = new MimeBodyPart();
      // create the Multipart and its parts to it
      Multipart mp = new MimeMultipart();
      //  add the Multipart to the message
      // send the message
    } catch (MessagingException mex) {
      Exception ex = null;
      if ((ex = mex.getNextException()) != null) {

Users who found this page were searching for:

  • Perl Binary Mode
  • java subtract method
  • python string to number
  • database programming microsoft sql server with java
  • returning empty arrays in perl
  • python working directory
  • python smtplib multiple receivers
  • java set read only file attribute
  • how to use comma in java

No comments yet.

Leave a Comment