How to Retrieve an Email Message Using Java Mail APIAs we know JavaMail API is a convenient way of sending and retrieving email message in a J2EE based web application. Here we will discuss the procedure of retrieving the email from respective inbox folder by using JavaMail API. For accomplishing this, the J2ee component (which we are using in our application to retrieve the mail) needs to connect to the mail server and retrieve a session. After this, it requests for the INBOX which contains the email messages. For getting access to it, the email requestor needs to authenticate itself. For understanding this in detail consider the following example: import javax.mail.*; public class RetrievingMail Here we have declared three String objects: myhost, username and pwd. After this an instance of Property object is passed to the getDefaultInstance() method to create a session. Session object is here referred as sess1. Then we have created Store and Folder objects which are denoted as store11 and folder11. store11 is created using getStore() method which uses pop3 as argument because POP3 protocol is used to store the messages. Now access to INBOX folder is retrieved using getFolder() method. After this we have used three methods: getMessage() which retrieves the messages from the folder which are represented through array of messages here. Next is getFrom() method which displayed the sender’s name and third method is getSubject() which retrieves the subject line of the email mesaage. Here after displaying the sender’s name and subject of mail we have asked the email requestor whether he or she would like to read the message or not. The response of client is assigned to the variable firstline and then we have used if loop to evaluate his or her response. If client wants to read or his response is ‘Y’ we have retrieved the email message body using an another method getContent().
| All About Different Types of XML Editors | Generating XML Document Using JSP | How to Retrieve an Email Message Using Java Mail API | How to Send an Email Message Using Java Mail API | Transforming XML Data with XSLT | Understanding Basic Components of a JMS Program | Understanding Basic Technology of ebXML | Understanding Deployment Descriptor in Reference with Servlets | Understanding eXtensible Access Control Markup Language (XACML) | Understanding the Design Goals of XML | Understanding XML Common Biometric Format | |
|
|||
|
||||
“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”
Copyright - © 2004 - 2019 - All Rights Reserved.