Java Mail اسئلة واجوبة المقابلات
Question: How to show all header information of message using Java Mail api?Answer: We will use method given below to retrieve all header information, this method returns Enumerations type.public Enumeration getAllHeaders(); package com.withoutbook.common; import javax.mail.*; import javax.mail.internet.*; import java.util.*; public class AllHeaderClient { 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_ONLY); Message[] messages = folder.getMessages(); for (int i = 0; i < messages.length; i++) { System.out.println("------------ Message " + (i + 1) + " ------------"); // Here's the difference... Enumeration headers = messages[i].getAllHeaders(); while (headers.hasMoreElements()) { Header h = (Header) headers.nextElement(); System.out.println(h.getName() + ": " + h.getValue()); } System.out.println(); } } } |
احفظ للمراجعة
احفظ هذا العنصر في الإشارات المرجعية، او حدده كصعب، او ضعه في مجموعة مراجعة.
سجل الدخول لحفظ الإشارات المرجعية والاسئلة الصعبة ومجموعات المراجعة.
هل هذا مفيد؟ نعم لا
الاكثر فائدة حسب تقييم المستخدمين:
- What is JavaMail?
- Explain POP, SMTP and IMAP protocols.
- Discuss about JavaMail.
- Explain the structure of Javamail API
- What are the advantages of JavaMail?