Introduction to JavaMail Api
JavaMail API is used to read, write and compose E-mails (Electronic messages). The JavaMail API provides a framework to create mail and messaging client applications using Java by platform-independent and protocol-independent. The JavaMail API provides the abstract class which contains the object defined in the mailing system and also performs an interface to E-mail Applications. JavaMail API is commonly used for reading and sending E-mails and needs service providers to interact with mailing servers that execute on the transport protocol.
Overview of JavaMail API
JavaMail API provides a framework to create mail and messaging client applications by platform-independent and protocol-independent. The JavaMail API provides a set of abstract class which contains the object comprises the mailing system and also performs an interface to E-mail applications. It is generally used for composing, reading, and sending E-Mails (Electronic Messages). JavaMail API is a set of API’s that is used for a mailing system and it offers services for sending and reading E-mails. JavaMail offers an element that is used to construct an interface for a messaging system with interfaces and system components. JavaMail includes various classes which implement the MIME Internet Messaging Standards and RFC822; those classes are in the JavaMail class packages.
Protocols used in JavaMail API
Several protocols are used in JavaMail API, they are as follows,
- NNTP and Others
SMPT (Simple Mail Transfer Protocol): It provides the mechanism for delivering the E-mails and it is an Internet Standard for receiving and sending E-mail across the IP Networks which uses the TCP with the most acceptable port 25 to send and receive emails. It has secure SSL connections. The JavaMail API has the core classes and packages in com.sun.mail.smtp this will perform SMTP protocol provider to make a connection with any SMTP servers. We can make use of the Postcast Server, email Server, Apache James Server as on SMTP Server. Once purchasing the host-space by default SMTP Server provides us the hosting provider.
POP (Post Office Protocol): It is also called POP3, the main thing to provides the mechanism to receive the E-mails. It defines and maintains the particular/single Mailbox for every single user. The POP3 protocol is defined in RFC 1939. POP3 is a Standard Internet Protocol used by the Local E-mail Clients to right to use E-mail from Remote Server over TCP/IP protocols and it listens to the Port 110. The provider of POP3 Protocol in JavaMail API is com.sun.mail.pop3.
IMAP (Internet Message Access Protocol): It is the most advanced protocol for receiving messages. IMAP offers support for numerous Mailboxes for every user; additionally, the Mailboxes can be contributed to several various users. This IMAP is defined in RFC 2060 and it listens to Port 143. The provider of IMAP Protocol in JavaMail API is com.sun.mail.imap. IMAP over SSL uses the assigned port 993.
MIME (Multipurpose Internet Mail Extension): It defines and tells the browser about what the content is being transferred it does not have a mailing transfer protocol it only tells that what is actually sent for example any attachment, format of messages being sent, and so on. For various documents they have different effects they are RFC 2047, RFC 2046, RFC 2045, AND RFC 822, those formats are exist and used in the mail program itself.
NNTP (News Transfer Protocol) and others: There are several protocols which are provided by the Third-Party Organisers and some are NNTP, S/MIME (Secure Multipurpose Internet Mail Extension), and so on.
As said earlier, Java Application uses JavaMail API to read, write and compose E-mails (Electronic messages). The JavaMail API provides a framework to create mail and messaging client applications using Java by platform-independent and protocol-independent. JavaMail API makes use of the SPI (Service Provider Interface) which is an intermediate service to the application of Java deals with various protocols. Let’s see the following architecture which describes the flow of JavaMail,
The conceptual mechanism of JavaMail API is related to other J2EE API’s like JNDI, JDBC, and JMS, by seeing the above architectural diagram the JavaMail API is divided into two essential parts,
- Application-Independent: This part is an Application Programming Interface (API) which is used by the application components for sending and receiving the mailing messages. It underlies the independent provider or protocol used.
- Service-Dependent: this part is a Service Provider Interface (SPI) which tells about the protocol-specific languages like POP, IMAP, SMTP, and NNTP. It is based on the plug-in provider of E-mail service to the J2EE Platform.
In JavaMail API properties, there are only a few recognized properties referenced in javax. mail execution which comes up with J2EE reference implementation, those properties are set as Strings in that the type column defines that how the string is interpreted. Let’s see few properties as follows,
IMAP Configuration Properties
|Mail. imap.host||String||IMAP server to the connection – connect to|
|Mail. imap.user||String||The default user for IMAP – user name|
SMTP Configuration Properties
|mail. smtp.port||int||It symbolizes the connection to the port. It sets the default to 25.|
|mail. smtp.timeout||int||The default timeout is infinite. The I/O timeout value defines in milliseconds.|
POP3 Configuration Properties
|Mail.pop3.host||String||POP3 server to the connection – connect to|
|Mail.pop3.user||String||The default user for POP3 – user name|
API provides classes that model a mail system
In JavaMail API there are various Interfaces and Classes which is used to Read, Send and Delete E-mail messages. There are two main packages which is used in JavaMail API they are javax. mail and javax. mail.internet packages. Those packages contain with core classes they are as follows,
|Javax.mail.Message||It is an e-mail message which models the abstract class. The sub-class provides the implementations|
|Javax.mail.Session||This is the main key class of API. It represents the connection factory and it is a multi-threaded object.|
|Javax.mail.Address||Their sub-class provides the implementations. The abstract class describes the addresses from end-to-end in the message.|
|Javax.mail.Transport||It is a message transport mechanism for sending/transferring E-mail messages.|
|Javax. mail.Authenticator||This is used to secure the mailing resources on the mail server.|
|Javax.mail.internet.MimeMessage||It is an E-mail messaging service that understands the MIME types (what is being used like formats etc.) and headers. It works on the sub-classes. The messages are abstract class.|
|Javax. mail.Store||This purpose is to models a message store and accessing protocol for retrieving and storing the messages. The Stores is separated into folders.|
|Javax. mail.Folder||It contains the sub-folders and the class represents a folder structure of mail messages.|
|The InternetAddress class represents an internal address of e-mail that uses the syntax of RFC822. The address format will be email@example.com or the Personal Name firstname.lastname@example.org
In this article, I have explained the JavaMail API. Hope the article helps you to understand.
This is a guide to JavaMail Api. Here we discuss the JavaMail includes various classes which implement the MIME Internet Messaging Standards. You may also have a look at the following articles to learn more –