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

    Question JavaMail help needed

    Hi this is the error message im getting...

    Cannot send email: javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. z55sm3960650eeh.21

    please help....

    The code im sending is:



    public void sendEmail(final String p_fromEmailAdd, final String[] p_toEmailAddresses, String p_emailSubject, String p_emailBody)

    {
    String host = "smtp.gmail.com";
    String from = "username";
    String pass = "password";
    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();
    }
    catch(MessagingException ex)
    {
    System.err.println("Cannot send email: " + ex);
    }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default

    This question has been asked and answered before; search these forums for STARTTLS and you'll find the thread.

    kind regards,

    Jos

  3. #3
    alabama is offline Member
    Join Date
    Aug 2010
    Posts
    3
    Rep Power
    0

Similar Threads

  1. Javamail
    By johniem in forum New To Java
    Replies: 0
    Last Post: 07-14-2010, 03:00 PM
  2. JavaMail API
    By eponcedeleon in forum Advanced Java
    Replies: 1
    Last Post: 02-28-2010, 12:39 AM
  3. JavaMail Jar
    By rummy in forum Advanced Java
    Replies: 1
    Last Post: 01-21-2010, 03:51 PM
  4. Javamail
    By v_mallikarjun in forum Advanced Java
    Replies: 14
    Last Post: 04-18-2008, 07:32 PM
  5. Using JavaMail API
    By consult4u in forum Networking
    Replies: 0
    Last Post: 08-09-2007, 10:15 AM

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
  •