Die meistgefragten Interviewfragen und Antworten sowie Online-Tests
Lernplattform fur Interviewvorbereitung, Online-Tests, Tutorials und Live-Ubungen

Baue deine Fahigkeiten mit fokussierten Lernpfaden, Probetests und interviewreifem Inhalt aus.

WithoutBook vereint themenbezogene Interviewfragen, Online-Ubungstests, Tutorials und Vergleichsleitfaden in einem responsiven Lernbereich.

Interview vorbereiten

Probeprufungen

Als Startseite festlegen

Diese Seite als Lesezeichen speichern

E-Mail-Adresse abonnieren

Java Mail Interviewfragen und Antworten

Question: Sample code for sending multipart mail using JavaMail.
Answer: 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.


package com.withoutbook.common;

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.110";
String from = "test@localhost";
String to = "arindam@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 you read part1......");

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

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

msg.setContent(multipart);

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

Zum Wiederholen speichern

Speichere diesen Eintrag als Lesezeichen, markiere ihn als schwierig oder lege ihn in einem Wiederholungsset ab.

Meine Lernbibliothek offnen
Ist das hilfreich? Ja Nein

Am hilfreichsten laut Nutzern:

Copyright © 2026, WithoutBook.