import java.util.Properties;
import javax.mail.BodyPart;
import javax.mail.Message;
import javax.mail.Multipart;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
public class HtmlMail
{
public HtmlMail()
{
try {
String from = "Avi";
String to = "xxx@gmail.com";
String body = "This is HTML";
String subject = "HTML";
MimeMessage message = new MimeMessage(getLocalSession());
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(subject);
Multipart multipart = new MimeMultipart();
BodyPart htmlPart = new MimeBodyPart();
htmlPart.setContent(body,"text/html");
htmlPart.setDisposition(BodyPart.INLINE);
multipart.addBodyPart(htmlPart);
message.setContent(multipart);
Transport.send(message);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Session getLocalSession() {
Properties props = System.getProperties();
props.put("mail.smtp.host", "100.100.100.100");
return Session.getDefaultInstance(props, null);
}
public static void main(String[] args) {
new HtmlMail();
}
}