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 for replying to messages using JavaMail.
Reponse : The Message class have a reply() method to configure a new Message with the proper recipient and subject, adding "Re: " if not already there. This does not add any content to the message, reply() method have a boolean parameter indicating whether to reply to only the sender (false) or reply to all (true).

MimeMessage reply = (MimeMessage)message.reply(false);reply.setFrom(new InternetAddress("president@whitehouse.gov"));reply.setText("Thanks");Transport.send(reply);

To configure the reply-to address when sending a message, use the setReplyTo() method.


package com.withoutbook.common;

import java.io.*;
import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;

public class ReplyMail {

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

Date date = null;
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", "192.168.10.110");

Session session = Session.getDefaultInstance(properties);

Store store = session.getStore("pop3");
store.connect("192.168.10.110", "arindam", "arindam");

Folder folder = store.getFolder("inbox");
if (!folder.exists()) {
System.out.println("inbox not found");
System.exit(0);
}
folder.open(Folder.READ_ONLY);

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

Message[] message = folder.getMessages();
if (message.length != 0) {
System.out.println("no. From ttSubject ttDate");
for (int i = 0, n = message.length; i < n; i++) {
date = message[i].getSentDate();

System.out.println(" " + (i + 1) + ": " + message[i].getFrom()[0] + "t" +
message[i].getSubject() + " t" + date.getDate() + "/" +
date.getMonth() + "/" + (date.getYear() + 1900));
System.out.print("Do you want to reply [y/n] : ");
String ans = reader.readLine();
if ("Y".equals(ans) || "y".equals(ans)) {

// Create a reply message
MimeMessage reply = (MimeMessage) message[i].reply(false);

// Set the from field
reply.setFrom(message[i].getFrom()[0]);

// Create the reply content
// Create the reply content, copying over the original if text
MimeMessage orig = (MimeMessage) message[i];
StringBuffer buffer = new StringBuffer("Thanksnn");
if (orig.isMimeType("text/plain")) {
String content = (String) orig.getContent();
StringReader contentReader = new StringReader(content);
BufferedReader br = new BufferedReader(contentReader);
String contentLine;
while ((contentLine = br.readLine()) != null) {
buffer.append("> ");
buffer.append(contentLine);
buffer.append("rn");
}
}
// Set the content
reply.setText(buffer.toString());

// Send the message
Transport.send(reply);

} else if ("n".equals(ans)) {
break;
}
}

} else {
System.out.println("There is no msg....");
}

}
}

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.