Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
JavaMail Overview
Contents:
Javamail API Related Protocols Javamail API Core Classes Javamail Client Service Using the Javamail API
After completing the next session, you will be able to: Understand the Javamail API
JavaMail API
Javamail is an API for reading, composing and sending electronic messages (e-mails). Javamail API is designed to provide protocol-independent access for sending and receiving mails.
After completing the next session, you will be able to: Understand different protocols related to sending and receiving of mails
Procotols
SMTP (Simple Mail Transfer Protocol) POP (Post Office Protocol) IMAP (Internet Message Access Protocol) NNTP (Network News Transfer Protocol) MIME (Multipurpose Internet Mail Extensions)
Mechanism for users to get their mails Supports single mailbox for each user Messages are downloaded by client email programs and deleted from the server Currently in version 3 and often called POP3
More advanced protocol for receiving messages stored on a mail server. Permits client email programs to access remote message stores as if they were local. Permits users to access messages from more than one machine.
A specification for formatting non ASCII messages Defines the content and format of what is transferred. Many email client programs support MIME which enables them to send audio, video and graphics files.
The protocol used to send, distribute, and retrieve USENET messages. USENET is a bulletin board service containing forums called newsgroups that cover various interest groups
You should now be able to: Understand different protocols related to sending and receiving of mails
After completing the next session, you will be able to: Understand the Javamail API Core Classes
Core Classes javax.mail.Session defines a basic mail Session. Uses the java.util Properties Object to get information like mail server, sender details, username, password etc. javax.mail.internet.MimeMessage an email Message that understands MIME types and headers.
javax.mail.Address Used to specify email addresses javax.mail.Authenticator Used to access protected resources (mail server) via a username and password. javax.mail.Transport This class speaks the protocol-specific language for sending the message (usually SMTP). javax.mail.Store and javax.mail.Folder Use Store to specify which protocol (Ex. POP3) to use and Folder to read messages (Ex. INBOX)
You should now be able to: Understand the Javamail API Core Classes
After completing the next session, you will be able to: Understand the Java Mail Client Service
Adds e-mail and news capabilities to applications deployed on the SAP J2EE Engine. Provides APIs for access to SMTP, POP3, IMAP4, and NNTP mail servers, for transporting, storing, and accessing a message or news on Internet or your network
You should now be able to: Understand the Javamail Client Service
After completing the next session, you will be able to: Understand how send a message
Create a mail Session providing the server details Create the message to send Provide the sender, receiver addresses Send the message
//Step 1. Create an initialcontext ctx = new InitialContext(); //Step 2. Lookup the JNDI name for resource type //javax.mail.Session Session session = (Session)ctx.lookup("java:comp/env/mail/Email");
/* Step 3. Retreive the properties set in the MailSession mail.smtp.host contains the SMTP Mail Server name mail.from contains the Sender's e-mail id
**/
Properties props = session.getProperties(); out.println ( "Mail from >> " + props.getProperty("mail.from")); out.println ( "SMTP Server >> " + props.getProperty("mail.smtp.host"));
message.setSubject(request.getParameter("Subject"));
message.setContent(request.getParameter("Message"), "text/plain");
out.println(<br><b>Thank you. Your message to " + request.getParameter("Recipient") + " was successfully sent.</b>");
You should now be able to: Understand the Javamail API Understand different protocols related to sending and receiving of mails Understand the Javamail Client Service Understand how send a message