REGISTER FREE to Receive Instant Job

Friday, 13 February 2015

Sending email with Html content using JavaMail API

Java Provide JavaMail API to compose, write and read electronic messages (emails).The JavaMail API provides protocol-independent and plateform-independent framework for sending and receiving mails.
Java Provide two mail package javax.mail and javax.mail.activation contains the core classes of JavaMail API.
Protocols used in JavaMail API

There are some protocols that are used in JavaMail API.
  • SMTP
  • POP
  • IMAP
  • MIME
  • NNTP and others
Sending email with Html content using JavaMail API

//Example of sending email with attachment using JavaMail API

package sendMail; // package name

import java.util.Properties;  

import javax.mail.*;  
import javax.mail.internet.*;  
  
public class SendMailSSL {  // class name
 public static void main(String[] args) {  
  
 
 String to="jobsacid@gmail.com";//change accordingly your gmail ID
 final String user="admin@jobsacid.com";//change accordingly host email ID
 final String password="xxxxx";//change accordingly your password 
  
 //1) get the session object    
 Properties properties = System.getProperties();  
 properties.setProperty("mail.smtp.host", "mail.jobsacid.com");  /// host name
 properties.put("mail.smtp.auth", "true");  
 Session session = Session.getDefaultInstance(properties,  
  new javax.mail.Authenticator() {  
  protected PasswordAuthentication getPasswordAuthentication() {  
  return new PasswordAuthentication(user,password);  
  }  
 });  
    
 //2) compose message     
 try{  
     MimeMessage message = new MimeMessage(session);  
     message.setFrom(new InternetAddress(user));  
     message.addRecipient(Message.RecipientType.TO,  
                              new InternetAddress(to));  

    message.setSubject("HTML Message");  
    message.setContent("<h1>sending html mail check</h1>","text/html" );  

   Transport.send(message);  
     System.out.println("message sent....");  
  }catch (MessagingException ex) {ex.printStackTrace();}   
}  
}

6 comments:

  1. Thanks for your informative post on Java application development. This open source platform assists software developers to create stunning mobile application with ease. Further, they can make use of this platform at free of cost. J2EE Training in Chennai | JAVA Training in Chennai

    ReplyDelete
    Replies
    1. The share your really gives us excitement. Thanks for your sharing. If you feel tired at work or study try to participate in our games to bring the most exciting feeling. Thank you!
      hotmail sign in | red ball game | 192.168.1.1

      Delete
  2. WP EasyCart eCommerce module is a straightforward shopping basket module that introduces into new or existing WordPress online journals and sites. Get a full WordPress eCommerce Shopping Cart framework inside minutes! Offer retail items, advanced downloadable merchandise, blessing cards and that's only the tip of the iceberg! What's more, now with WordPress, the capable components are still simple to administrate!
    Wordpress Cart Shop

    ReplyDelete
  3. I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. I like play game five nights at freddy’s 4, game word cookies game , game hill climb racing 2 , hotmail login, and u? I hope people visit my website.

    ReplyDelete

Popular Posts

Powered by Blogger.

About Me

My photo

JobsAcid is a 'job search engine' to provide finding a job on the internet easier for the user. It has designed as huge selection of job offerings on the same search engine.