Java Mail Questions et reponses d'entretien
Question : Sample code for reading attachment message using JavaMail.Reponse : Java Mail API provides classes to send multiple Mime body part with one Mime Message. MulipltMimeBody parts can be text, file or image. All message are stored in Folder objects. folders can contain folders or messages. The Folder class declares methods that fetch, append, copy and delete messages, and message contain Attachment.package com.withoutbook.common; import java.io.*; import java.util.*; import javax.mail.*; public class ReadAttachment { public static void main(String args[]) throws Exception { String host = "192.168.10.110"; String user = "arindam"; String password = "arindam"; // Get system properties Properties properties = System.getProperties(); // Get the default Session object. Session session = Session.getDefaultInstance(properties); // Get a Store object that implements the specified protocol. Store store = session.getStore("pop3"); //Connect to the current host using the specified username and password. store.connect(host, user, password); //Create a Folder object corresponding to the given name. Folder folder = store.getFolder("inbox"); // Open the Folder. folder.open(Folder.READ_WRITE); Message[] message = folder.getMessages(); for (int a = 0; a < message.length; a++) { System.out.println("-------------" + (a + 1) + "-----------"); System.out.println(message[a].getSentDate()); Multipart multipart = (Multipart) message[a].getContent(); //System.out.println(multipart.getCount()); for (int i = 0; i < multipart.getCount(); i++) { //System.out.println(i); //System.out.println(multipart.getContentType()); BodyPart bodyPart = multipart.getBodyPart(i); InputStream stream = bodyPart.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(stream)); while (br.ready()) { System.out.println(br.readLine()); } System.out.println(); } System.out.println(); } folder.close(true); store.close(); } } |
Enregistrer pour revision
Ajoutez cet element aux favoris, marquez-le comme difficile ou placez-le dans un ensemble de revision.
Connectez-vous pour enregistrer des favoris, des questions difficiles et des ensembles de revision.
Est-ce utile ? Oui Non
Les plus utiles selon les utilisateurs :
- What is JavaMail?
- Explain POP, SMTP and IMAP protocols.
- Discuss about JavaMail.
- Explain the structure of Javamail API
- What are the advantages of JavaMail?