Session session = null;
if (emailUsername != null && emailUsername.length() > 0
&& emailUserpass != null && emailUserpass.length() > 0) {
// use SMTP Authentication
props.put("mail.smtp.auth", "true");
session = Session.getDefaultInstance(props, new SmtpAuthenticator(
emailUsername, emailUserpass));
} else {
// not use SMTP Authentication
session = Session.getDefaultInstance(props, null);
}