R4R
Right Place For Right Person TM
R4R JAVA JavaMailAPI

R4R
provide basic JavaMail Tutorials concept with JavaMail Examples . Through R4R you can develop JavaMail programming concept. R4R provide JavaMail Interview Questions with answers.R4R provide JavaMail Languages study materials in easy way.

JavaMail Tutorials

1.1    JavaMail Basic Tutorials

JAVAMAIL

Javamail is a Java  API which is used to send and receive email through SMTP,.POP3 and IMAP . JavaMail is built into the Java EE platform, but also provides an optional package for use in Java SE. The JavaMail API is  a platform-independent and protocol-independent framework which is used to build mail and appliction messaging. JavaMail is a set of abstract classes that create a framework for sending, receiving and handling e-mail, along with implementations of those classes. IMAP and SMTP allowing you to get started immediately on sending and receiving mail.  The javax.mail package defines classes that are common to all mail systems. Javamail  can be used to create personal mail filters, simple mailing lists and customized personal mail applications, as well as to add full e-mail capabilities to an Enterprise application or create a full-fledged e-mail client.

ROLE OF SMTP, IMAP ,AND POP3
SMTP Simple Mail Transfer Protocol :-- allows two mail servers to communicate using a simple language, and provides a step-by-step protocol for exchanging information.
IMAP Internet Mail Access Protocol:-
It is client/server  mail protocol. SMTP delivers mail to a central location, where the user can either log in and read it directly or use a client/server mail protocol to read it remotely. IMAP is keep mail on a remote server and let the user interact with it there.
POP3 Post Office Protocol:-
POP3 is  forward a user's mail to a single machine, where the user can go offline and read it, if necessary. IPOP3 is mainly used when connection is slow.

CLASSES OF JAVAMAIL API
JavaMail API contains number of classes few important of them are listed below

javax.mail.Session:-
it is the top-level class of javax.mail API its most commonly used methods provide the ability to control and load the classes    that represent the service provider implementations (SPI) for various mail protocols

javax.mail.Store:-it is implemented by a service provider, such as a POP Mail implementation developer. and allows for read, write, monitor, and search access for a particular mail protocol

javax.mail.Transport:
-This class send a message over a specific protocol.

javax.mail.Folder:
-It gives hierarchical organization to mail messages and provides access to e-mail messages in the form of javax.mail.Message class objects.

javax.mail.Message:-It  models all the details of an actual e-mail message, such as the subject line, sender/recipient e-mail address, sent date, and so on.

USES OF JAVAMAIL API
Possible uses of Javamail API are  following.

  1. Javamail API is used to send email from any type of java application.

  2. It is used to read ,compose, and sending email.

  3. The one of the important use of Javamail API is to create GUI mail client.

  4. It also used to send Email from java stored procedures and one of the important use of it ,is it help to search messages.

  5. It is important  to install javamail API to work with it.

EXAMPLE

This example is create to send message
1.import the package javax.mail  and then sub package javax.mail.internet.

import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;

2.create a class and declare the host address ,source address and destination address.as
public class SendMail {

    public static void main(String args[]) throws Exception {

        String host = "192.168.10.205";
        String from = "r4r@localhost";
        String to = "r4r@localhost"; 
3.Get system properties as:
 Properties properties = System.getProperties();
4.Setup mail server as:
       properties.setProperty("mail.smtp.host", host);

5. Get the default Session object. as:

 Session session = Session.getDefaultInstance(properties);

6. Create a default MimeMessage object. as:
  MimeMessage message = new MimeMessage(session);

7 Set the RFC 822 "From" header field using the value of the InternetAddress.getLocalAddress method.  as:

message.setFrom(
new InternetAddress(from));

8.Add the given addresses to the specified recipient type as:
 message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

9.Set the "Subject" header field as:
 message.setSubject("hello..!");

10. Sets the given String as this part's content,with a MIME type of "text/plain" as:
message.setText("Hello ......");

11.Send message
 Transport.send(message);

System.out.println("Message is Send.....");
   



Tolal:0 Click:
Show All Comments

Post Your Comments

Your Name:

Your Email ID :
Comments :
URL
  =* Enter SUM

New Updates

R4R
R4R
R4R
R4R
R4R
R4R
R4R
R4R