Home Javamail Send multipart mail using java mail



Send multipart mail using java mail
Posted on: December 15, 2008 at 12:00 AM
This Example shows you how to send multipart mail using java mail. Multipart is like a container that holds one or more body parts.

Send multipart mail using java mail

     

This Example shows you how to send multipart mail using java mail. Multipart is like a container that holds one or more body parts. When u send a multipart mail firstly create a Multipart class object and then create BodyPart class object, set text in BodyPart class object and add all BodyPart class object in Multipart class object and send the message. Class Multipart that we will use in this code is an abstract class. Method used in this program of Multipart class is.....

void addBodyPart(BodyPart part);

This method is used to add parts in multipart.

SendMultipartMail.java


import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

public class SendMultipartMail {

  public static void main(String args[]) throws Exception {

  String host = "192.168.10.205";
  String from = "test@localhost";
  String to = "komal@localhost";

  Properties properties = System.getProperties();
  properties.setProperty("mail.smtp.host", host);

  Session session = Session.getDefaultInstance(properties);

  Message msg = new MimeMessage(session);

  msg.setFrom(new InternetAddress(from));
  msg.addRecipient(Message.RecipientType.TO, 
new 
InternetAddress(to));
  msg.setSubject("MultiPart Mail");

  Multipart multipart = new MimeMultipart();

  BodyPart part1 = new MimeBodyPart();
 part1.setText("This is multipart mail and u read part1......");

 BodyPart part2 = new MimeBodyPart();
 part2.setText("This is multipart mail and u read part2......");

  multipart.addBodyPart(part1);
  multipart.addBodyPart(part2);

  msg.setContent(multipart);

  Transport.send(msg);
  System.out.println("Message send....");
  }
}

Output:

Message send....

Download code

Related Tags for Send multipart mail using java mail:
javacmailipusingthisailikecontainershowexamplesendtoexammultipartldwssheilmultiliulartinpartbodymntparjendhowpartsxaxampstipatoldkishamplartsarrtrtsvassthshoavhatldspleplndonolo


More Tutorials from this section

Ask Questions?    Discuss: Send multipart mail using java mail  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.