//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", smtphost);
props.put("mail.smtp.auth", "true");
// create autheticator object
Authenticator auth = new SMTPAuthenticator(user, pass);
// open session
Session session = Session.getDefaultInstance(props, auth);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address