Must issue a STARTTLS command first
Hi All,
Please help i get a "must issue a STARTTLS command first" error message with the below code, any help appreciated (including code clean up :-) )
public class Tester999
{
public static void main(String[] args)
{
StringBuffer x_emailMessageBody = new StringBuffer();
String x_subjectText = "Web " + x_df.format(new Date());
String x_emailSubject = null;
x_emailMessageBody.append("<br/>Regards,<br/>QA Team");
String[] x_emailAddresses = {"newmail.tester9@gmail.com"};
EmailSeleniumTestResults x_emailer = new EmailSeleniumTestResults();
x_emailer.sendEmail("Testering999@gmail.co.uk", x_emailAddresses,
x_emailSubject, x_emailMessageBody.toString());
}
/**
* Send the email
*/
public void sendEmail(final String p_fromEmailAdd, final String[] p_toEmailAddresses,
String p_emailSubject, String p_emailBody)
{
String host = "smtp.gmail.com";
String from = "Testering999";
String pass = "tester999";
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.user", from);
props.put("mail.smtp.password", pass);
props.put("mail.smtp.port", "587");
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session);
List<InternetAddress> x_emailAddressesList = new ArrayList<InternetAddress> ();
for (String str : p_toEmailAddresses)
{
try
{
x_emailAddressesList.add(new InternetAddress(str));
} catch (AddressException e)
{
e.printStackTrace();
}
}
Address[] x_toEmailAddresses = (InternetAddress[]) x_emailAddressesList
.toArray(new InternetAddress[x_emailAddressesList.size()]);
try
{
message.addRecipients(Message.RecipientType.TO, x_toEmailAddresses);
message.setSubject(p_emailSubject);
message.setContent(p_emailBody, "text/html");
Transport transport = session.getTransport("smtp");
transport.connect(host, 587, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}
}
}