List the protocal which is used in Java Mail API?
when you using JAVA MAIL API, before using these protocols used with the API. Mainly there are 4 types of protocols using in java mail api.
·         SMTP
·         POP
·         IMAP
·         MIME
Explain to the SMTP?
The SMTP using into the delivering mails. It is a mechanism, in a context of JavaMialAPI, the java mail program firstly communicated to with your company and internet service provider (ISP) SMTP server. Then SMTP server will the relay this message on the SMTP server of the recipient to eventually to be acquired by the user through POP or IMAP. It is not require SMTP server for open relay and authentication is supported. And it's user responsibility to ensure the SMTP server is configured properly. There is nothing in the JavaMail API for tasks like configuring a server to relay messages or to add and remove email accounts.
Explain to the POP?
POP is the mechanism used by most of the people on the internet used to get their mail Now latest  POP3 version ,RFC1939 defines this protocol. It is a supporter to support to single mailbox for each user. Actually more confusion occur to source, Much of what people are familiar when using POP. There are more mail message they have are not supported by POP at all. this capability are inbuilt into the program like as Microsoft Outlook. So, when using the JavaMail API, if you want this type of information, you have to calculate it yourself.
Explain to the IMAP?
It is the more advanced program to receiving message. and define to RFC 2060, now this time using version 4, also know as IMAP4. when using this protocol then time your mail server is supported this protocol. when you using IMAP ,that time you can't change your program instead of POP and expect everything in IMAP to be supported. IMAP supported your mail server, java mail-based can take the advantage of users using multiple folders for multiple users.
Explain to the MIME?
MIME is not a mail transfer protocol. Actually it is defined which type of mail is transferred, this extension check the format of the messages, attachment and so on. many different documents are take effect here: RFC 822, RFC 2045, RFC 2046, and RFC 2047. If the user is using java Mail Api, you don't need to worry about these format. these formats use in the program or access in your program.
Explain to the NNTP?
The split of in java mail Api between provider and everything else, if you want to se another additional protocol, you are simply or easily using to add support for additional protocols. Sun maintains a list of third party providers, the main advantages and sun does not support to the out -of -the box. then time you find the NNTP and S/MIME (Secure/MIME) and more.
How to install to the Java mail API?
If you want to using JavaMailAPI, then download the JavaMail implementation, unbundled the javamail-[version].zip file , and to mail. jar file to your CLASSPATH. then implementation using the comes with an SMTP, IMAP4, and POP3. it is provider to besides the core classes.
Note: If you installing Sun's JavaMail implementation,  After installing Sun's JavaMail implementation, you can find many example programs in the demo directory.
There are two versions are using in this time for JavaMail implementation, 1.2 and 1.1.3, and 1.2 is the latest version using today. The 1.1.3 version included with 1.2.1version of the java 2 platform, it is known J2EE(Enterprise Edition) so, it's commonly used . The JavaMail responsible use affects what you download and install. All will work with JDK 1.1.6+, Java 2 Platform, Standard Edition (J2SE) version 1.2.x, and J2SE version 1.3.x . when you are totally install the JavaMail implementation after then install JavaBeans Activation Framework.
Explain the step of the installation of JavaMail API?
you will install Sun's JavaMail reference implementation .After you install the Sun's JavaMail reference then introduce the demonstration programs that come with the reference implementation.
Then using the some special Task to established JavaMail API Environment setup:
Task 1: firstly Download the latest version of the JavaMail Implementation from Sun.
Task 2: After JavaMail download to latest version for JavaBeans Activation Framework from Sun.
Task 3: Then both downloaded packages Unzip. you get the ZIP file for all platform for both packages.
Task 4: using the jar tool to Unzip these packages .
Task 5: Add the mail.jar file from the JavaMail 1.2 download and the activation.jar file from the JavaBeans    Activation Framework download to your CLASSPATH.
Task 6: Then total files copy into your extension library directory. The default installation copy using for Microsoft Windows, the command look like the following:
cd javamail-1.2
copy mail.jar jdkjrelibext
cd jaf-1.0.1
copy activation.jar jdkjrelibext
Task 7: After that Go into the demo directory. The demo directory comes with the JavaMail API implementation and compile to the msgsend program to send a test message.
Task 8: The msgsend program compile to javac msgsend.java
Task 9: Execute the program passing in a from address with the -o option, your SMTP server with the -M option, and the to address (with no option). You'll then enter the subject, the text of your message, and the end-of-file character (CTRL-Z) to signal the end of the message input.
Task 10: Then lastly check to make sure your message received with normal mail reader (Eudora, Outlook Express, pine, ...)
How can i read message with Java Mail API?
If you want to read the Mail or Messages using for JavaMail API. There are all messages are stored in a Folder object. and this folder contains to all folders and messages. Some important methods are inbuit in this program.
Session.getProperties();
session.getstore("pop3")
store.connect(hostname,username,and password)
store.getFolder("inbox")
folder.open(Folder.READ_ONLY),folder.getMessages().
public class readmail
{
 public static void main(String args[])
{
  String host = "192.168.10.255";
  String username = "r4r@localhost";
  String password = "r4r@localhost";
Properties props = new Properties();
// Get session
Session session = Session.getDefaultInstance(props, null);
// Get the store
Store store = session.getStore("pop3");
store.connect(host, username, password);
// Get folder
Folder folder = store.getFolder("INBOX");
folder.open(Folder.READ_ONLY);
// Get directory
Message message[] = folder.getMessages();
for (int i=0; n=message.length; i<n; i++) {
   System.out.println(i + ": " + message[i].getFrom()[0]
    + "t" + message[i].getSubject());
}
// Close connection
folder.close(false);
store.close();
}
}
How to send HTML mail to client?
If you want to send an HTML E-Mail from your machine. Now it is assumed that your local host connected to the internet and it's capable for send an E-Mail. That time you using the  setContent() method to set the content and second argument is "text/html" . The "text/html" is specify that HTML content is including in the message.
public class HTMLMailSend
  public static void main(String [] args)
   {
      // Recipient's email ID needs to be mentioned.
      String to = "r4r@localhost";
     // Sender's email ID needs to be mentioned
      String from = "r4r111@localhost";
      // Assuming you are sending email from localhost
      String host = "localhost";
     // Get system properties
      Properties properties = System.getProperties();
      // Setup mail server
      properties.setProperty("mail.smtp.host", host);
      // Get the default Session object.
      Session session = Session.getDefaultInstance(properties);
      try{
         // Create a default MimeMessage object.
         MimeMessage message = new MimeMessage(session);
         // Set From: header field of the header.
         message.setFrom(new InternetAddress(from));
         // Set To: header field of the header.
         message.addRecipient(Message.RecipientType.TO,
                                  new InternetAddress(to));
         // Set Subject: header field
         message.setSubject("This is the Subject Line!");
         // Send the actual HTML message, as big as you like
         message.setContent("<h1>This is the HTML MAIL SEND PROGRAM</h1>",
                            "text/html" );
         // Send message
         Transport.send(message);
         System.out.println("Sent message successfully....");
      }catch (MessagingException mex) {
       mex.printStackTrace();
      }
   }
}
How to forword mail to the sender?
When you want to forward Mails or Messages. for directly forwarding for one or many E-mails. Then in Forwarding Messages is a little more involved. You forwarding the message for using JavaMail API. there is no only one method to call .Actually a Mail Messages can be made up of multiple parts. The Every part is BodyPart, or more specifically, and when working you MIME Messages then a MimeBodyPart. the other or different BodyPart is get combined into a container, this container also called Multipart or, again, more specifically a MimeMultipart. When forwarding messages then it's very essentially using DataHandler. to copy the content one message to another, just copy over it's DataHandler. The DataHandler class from JavaBean Activation Framework.
Can i attach the image in our message?
Yes, If you want to send  images then attach images in to your Mesages and then send. you using JavaMail API attach your image. This images attachment and  reference the image with a special cid URL, where the cid is a reference to the Content-ID header of the image attachment. The attaching images or embedding images on your messages like as similar to attaching the file in your message. The only difference for you have to tell the MimeMultipart that the part are related by setting it's subtype. The subtype in the Constructor or setSubType () and set the Content-ID header for the image to a random string which is used as the src for the image in the img tag. The following demonstrates this completely.
Can i send multipart mail?

The MultiPart Mail is like a special type container. And this Multi Part container holds one or more body Parts. When you want to send a Multi Part Mail then firstly create a Multi Part class object, after create a BodyPart class object, you set total text in class BodyPart class object and all BodyPart class object in Multipart class object and send the message. In Abstract class in use code for Multi Part class. The using method in this MultiPart class is  void addBodyPart(BodyPart part);
Request to Download PDF

Post A Comment:

0 comments: