Presentation is loading. Please wait.

Presentation is loading. Please wait.

JAVA MAIL API. High level representation of the basic components of any mail system. The components are represented by abstract classes in the javax.mail.

Similar presentations


Presentation on theme: "JAVA MAIL API. High level representation of the basic components of any mail system. The components are represented by abstract classes in the javax.mail."— Presentation transcript:

1 JAVA MAIL API

2 High level representation of the basic components of any mail system. The components are represented by abstract classes in the javax.mail package. These classes are all abstract because they don’t make many assumptions about how the email is stored or transferred between machines.

3 JavaMail API is a standard extension to Java, not part of the core JDK or JRE class library. Consequently there’ll need to download it separately from Sun. Download “mail.jar”. This file contains the actual.class file that implement the JavaMail API. Add this file to the class path OR simply place it in jre/lib/ext directory.

4 Java Mail API uses JavaBeans Activation Framework(JAF) to describe and display multilingual text and encoded multimedia data. The JavaBeans Activation Framework is also a standard extension to Java, not part of the core API. Download “activation.jar” file and place it in the class path.

5 Sending Email 1.Set the “mail.host” property to point the local mail server- Properties props = new Properties() props.put("mail.host",“ "); It can be like:: alt2.gmail-smtp-in.l.google.com

6 How to know about mail server Open a DOS Command Prompt Type "nslookup". Your computer's DNS Server name and IP address will be displayed. Type "set type=mx" This will cause NSLOOKUP to only return what are known as MX (Mail eXchange) records from the DNS servers.

7

8 Step 2 These properties are used to retrieve a Session object from the Session.getInstance() method like this- Session mailConnection = Session.getInstance(props,null); Session object represents an ongoing communication between a program and one mail server. The second argument to the getInstance(), null here is a javax.mail.Authenticator that ask the user for a password if requested by the server.

9 Step 3 Session object is used to create a new Message object- Message msg=new MimeMessage(mailConnection); MimeMessage is used to send Internet email.

10 Step 4 Set up from address and to address- Address fromMy=new InternetAddress(ajayinvns@gmail.com,”aj ay”);ajayinvns@gmail.com,”aj ay Address toMy= new InternetAddress(ajayinvns@gmail.com);ajayinvns@gmail.com

11 Step 5 Set up from header- Msg.setFrom(fromMy);

12 Step 6 Set up the To header- Not only specify the address that the message will be sent to but how that address is used i.e. TO, Cc, or Bcc. This is done by Message.RecipientType.TO Message.RecipientType.CC Message.RecipientType.BCC Set the to header- Msg.setRecipient(Message.RecipientType.TO, toMy);

13 Step 7 Set message subject- Msg.setSubject(“This is Subject Line”);

14 Step 8 Set up the content of message- msg.setContent(“TextTextText”, “text/plain”);

15 Step 9 Send the message- Transport.send(msg); Example to Send Email

16 Receiving Mail


Download ppt "JAVA MAIL API. High level representation of the basic components of any mail system. The components are represented by abstract classes in the javax.mail."

Similar presentations


Ads by Google