private void SendMailWithoutAttachments() {
Authenticator authenticator = null;
try {
lastError = "";
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTPHost);
if (auth == true)
props.put("mail.smtp.auth", "true");
else
props.put("mail.smtp.auth", "false");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.port", Port.toString());
if (auth == true) {
authenticator = new SMTPAuthenticator();
}
Session session = Session.getInstance(props, authenticator);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(SenderMailAdress);
msg.setFrom(addressFrom);
// Set the Receiver mail adresses
InternetAddress[] addressTo = new InternetAddress[To.getSize()];
for (int i = 0; i < To.getSize(); i++) {
addressTo[i] = new InternetAddress((String) To.Get(i));
}
msg.setRecipients(MimeMessage.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(Subject);
if (htmlMail == true)
msg.setContent(MsgText, CONTENT_HTML);
else
msg.setContent(MsgText, CONTENT_TEXT);
}
Transport.send(msg);
} catch (MessagingException mex) {
mex.printStackTrace();
lastError = "Method: sendMail" + crLF + mex.toString();
Exception ex = null;
if ((ex = mex.getNextException()) != null) {
ex.printStackTrace();
lastError = "Method: sendMail" + crLF + ex.toString();
}
}
}