Sending email with Html content

As we send the email, we can send the html content moreover.

For better comprehension of this illustration, take in the progressions of sending email utilizing JavaMail API first.

For getting or sending the email utilizing JavaMail API, you have to stack the two jug records:

  • mail.jar
  • activation.jar

download these jar files go to the Oracle site to download the latest version.

Sample of sending email with html substance utilizing JavaMail API

import java.util.*;  
import javax.mail.*;  
import javax.mail.internet.*;  
import javax.activation.*;  
class SendHtmlEmail  
   public static void main(String [] args)  
      String host="";//change as needs be   
      String to="";//change as needs be   
      final String user="";//change as needs be   
      final String password="*******";//change as needs be   
      Properties properties = System.getProperties();  
      properties.setProperty("", );  
      properties.put("mail.smtp.auth", "true");  
      Session session = Session.getDefaultInstance(properties,  
    new javax.mail.Authenticator() {  
     protected PasswordAuthentication getPasswordAuthentication() {  
      return new PasswordAuthentication(user,password);  
         MimeMessage message = new MimeMessage(session);  
         message.setFrom(new InternetAddress(user));  
                                  new InternetAddress(to));  
        message.setSubject("HTML Message");  
        message.setContent("<h1>sending html mail check</h1>","text/html" );
         System.out.println("message sent....");  
      }catch (MessagingException ex) {ex.printStackTrace();}  
Load the jar file c:\> set classpath=mail.jar;activation.jar;.;
compile the source file c:\> javac
run by c:\> java SendHtmlEmail