JAVA MAIL API

JavaMail Projects

JavaMail Project 1

Send MultiPart Mail Using JavaMail API
Previous Home Next
adplus-dvertising

The MultiPart Mail is like a special type container. And this Multi Part container holds one or more body Parts. When you want to send a Multi Part Mail then firstly create a Multi Part class object, after create a BodyPart class object, you set total text in class BodyPart class object and all BodyPart class object in Multipart class object and send the message. In Abstract class in use code for Multi Part class. The using method in this MultiPart class is void addBodyPart(BodyPart part);

package R4R;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class sendmultipart {
  public static void main(String args[]) throws Exception {
  String host = "192.168.10.205";
  String from = "r4r@localhost";
  String to = "r4rrajesh@localhost";
  Properties properties = System.getProperties();
  properties.setProperty("mail.smtp.host", host);
  Session session = Session.getDefaultInstance(properties);
  Message message = new MimeMessage(session);
  message.setFrom(new InternetAddress(from));
  message.addRecipient(Message.RecipientType.TO, 
new InternetAddress(to)); message.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); message.setContent(multipart); Transport.send(message); System.out.println("MultiPart Mail send...."); } }
Previous Home Next