Results 1 to 1 of 1
  1. #1
    alabama is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

    Cool 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();
    }
    }

    }
    Last edited by alabama; 08-25-2010 at 09:57 PM.

Similar Threads

  1. Does the JRE come with command to run?
    By gotenks05 in forum New To Java
    Replies: 5
    Last Post: 10-25-2008, 01:00 AM
  2. command
    By dirtycash in forum New To Java
    Replies: 8
    Last Post: 01-02-2008, 08:52 PM
  3. command help
    By dirtycash in forum New To Java
    Replies: 1
    Last Post: 12-05-2007, 01:24 AM
  4. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 01:23 AM
  5. how to issue the command of Ctrl-C (copy) in Java
    By bilal_ali_java in forum Advanced Java
    Replies: 0
    Last Post: 07-18-2007, 04:14 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •