Hello,
Use this code.
public static void sendMail(String to, String from, String subject, String message) throws Exception
{
//Create properties and session.
Properties props = new Properties();
props.put("mail.smtp.host", "servername");
Session session = Session.getDefaultInstance(props, null);
session.setDebug(false);
try
{
//Create a message
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = (InternetAddress[]) InternetAddress.parse(to);
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject);
msg.setSentDate( new Date() );
msg.setText(message);
Transport.send(msg);
}
catch( Exception e)
{
throw e;
}
}
Thanks and regards,
Pazhanikanthan. P