Use this code
String host = "";// give ur mail server name or IP I hope u will be having local mail server
// or configure gmail. Through that I think u can send mail.
// Get system properties
Properties props = System.getProperties();
// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth","true");
//props.setProperty("mail.smtp.dsn.notify",
// "SUCCESS,FAILURE ORCPT=rfc822;sachincr@gmail.com");
props.setProperty("mail.smtp.dsn.ret", "FULL");
// Get session
Session session = Session.getDefaultInstance(props, new Authenticator(){
protected PasswordAuthentication getPassWordAuthentication(){
return new PasswordAuthentication("userName","passwd"); // give ur username and passwd }
});
session.setDebug(true);
String[] mailingList = {"hjj@gmail.com","hjk.jk@rediffmail.com"};
// Define message
MimeMessage message = new MimeMessage(session);
try {
message.setFrom(new InternetAddress("sachincr@gmail.com"));
for (int i = 0; i < mailingList.length; i++) {
message.addRecipient(
Message.RecipientType.TO,
new InternetAddress(mailingList));
}
message.setSubject("This is my firts mail");
//message.setText("Welcome to JavaMail");
BodyPart messageBodyPart = new MimeBodyPart();
// Fill the message
//messageBodyPart.setText("Pardon Ideas");
String data ="HTML content of the file " // read the HTML file and store that into data variable
messageBodyPart.setContent(data,"text/html");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
// Send message
message.saveChanges(); // implicit with send()
Transport transport = session.getTransport("smtp");
transport.connect(host, "username", "passwd");// give ur username and passwd
transport.sendMessage(message, message.getAllRecipients());
transport.close();
} catch (MessagingException messagingException) {
messagingException.printStackTrace();
//System.exit(9); //
}
}