Questions et réponses d'entretien les plus demandées et tests en ligne
Plateforme d'apprentissage pour la preparation aux entretiens, les tests en ligne, les tutoriels et la pratique en direct

Developpez vos competences grace a des parcours cibles, des tests blancs et un contenu pret pour l'entretien.

WithoutBook rassemble des questions d'entretien par sujet, des tests pratiques en ligne, des tutoriels et des guides de comparaison dans un espace d'apprentissage reactif.

Preparation a l'entretien

Java Mail Questions et reponses d'entretien

Question : Sample code to send HTML mail with images using JavaMail.
Reponse : A client create new message by using Message subclass. It sets attributes like recipient address and the subject, and inserts the content into the Message object, and inserts the content into the Message object. Finally, it sends the Message by invoking the Transport.send() method.

The Transport class models the transport agent that routes a message to its destination addresses. This class provides methods that send a message to a list of recipients. Invoking the Transport.send() method with a Message object identifies the appropriate transport based on its destination addresses.


package com.withoutbook.common;

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

public class HTMLMail {

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

String host = "192.168.10.110";
String from = "arindam@localhost";
String to = "arindam@localhost";

// Get system properties
Properties properties = System.getProperties();

// Setup mail server
properties.setProperty("mail.smtp.host", host);

// Get the default Session object.
Session session = Session.getDefaultInstance(properties);

// Create a default MimeMessage object.
MimeMessage message = new MimeMessage(session);

// Set the RFC 822 "From" header field using the
// value of the InternetAddress.getLocalAddress method.
message.setFrom(new InternetAddress(from));

// Add the given addresses to the specified recipient type.
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));


// Set the "Subject" header field.
message.setSubject("hi..!");


String htmlText = "

Hello

" +
"";

// Sets the given String as this part's content,
// with a MIME type of "text/plain".
message.setContent(htmlText, "text/html");

// Send message
Transport.send(message);

System.out.println("Message Send.....");
}
}

Enregistrer pour revision

Ajoutez cet element aux favoris, marquez-le comme difficile ou placez-le dans un ensemble de revision.

Ouvrir ma bibliotheque d'apprentissage
Est-ce utile ? Oui Non

Les plus utiles selon les utilisateurs :

Copyright © 2026, WithoutBook.