Probably this will help
package com.medscape.prof.etutaf.common;
import javax.mail.*;
import javax.mail.internet.*;
public class SendEMail{
Session session;
public SendEMail(
String smtpHost) throws Exception {
java.util.Properties properties = System.getProperties();
System.out.println(smtpHost);
properties.put("mail.smtp.host", smtpHost);
session = Session.getInstance(properties,null);
}
public void mailto(String from, String to, String subject, String message) throws Exception {
System.out.println("inside mailto");
MimeMessage mimeMessage = new MimeMessage(session);
mimeMessage.setFrom(new InternetAddress(from));
mimeMessage.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
mimeMessage.setSubject(subject);
mimeMessage.setText(message);
System.out.println("before send");
try{
Transport.send(mimeMessage);
}
catch(NoSuchProviderException nse)
{
}
catch(Exception e) {
System.out.println("<br><br>" + e);
}
System.out.println("Sent!");
}
/*
public static void main(String []args) throws Exception {
System.out.print("Sending mail... ");
SendEMail sm = new SendEMail("172.16.16.107");
sm.mailto("from","to", "subject field", "message field"); System.out.println("Sent!");
}
*/
}