Here is working sample of javamail example to send a mail.


/**
 * @param args input param
 * @throws Throwable throws any exception
 */
public static void main(final String[] args) throws Throwable {
 
Properties propMgr = PropertyManager.load("system.properties");
 final Properties props = new Properties();
 props.setProperty("mail.transport.protocol", "smtp");
 props.setProperty("mail.host", "smtp.mymailserver.com");
 props.setProperty("mail.user", "username");
 props.setProperty("mail.password", "password");
 final Session mailSession = Session.getDefaultInstance(props, null);
 mailSession.setDebug(true);
 final Transport transport = mailSession.getTransport();
 final MimeMessage message = new MimeMessage(mailSession);
 message.setSubject("HTML  mail with images");
 message.setFrom(new InternetAddress("sender@company.com"));
 message.setContent("Cheers,Cashyup", "text/html");
 message.addRecipient(Message.RecipientType.TO,
   new InternetAddress(
   "receiver@company.com"));
 transport.connect();
 transport.sendMessage(message, message
   .getRecipients(Message.RecipientType.TO));
 transport.close();
}




Sandeep Joshi
Mathematics, Technology and Programming are my passion. I am a part of Java Ecosystem and through this blog, I contribute to it. I am here to blog about my interests, views and experiences.
I am on Google+ and Facebook.
I feel proud to be listed as a "National Memory Record Holder" in the Limca Book of Records, 2009 and have attempted for an International Memory record in the Guiness Book of Records. I can remember the value of PI upto 10,000 digits after the decimal (3.1415.....). You can contact me on javagenious.com(At)gmal.com ; I would like to hear from you :)