12 Replies Latest reply: Jul 11, 2012 1:28 AM by 248 RSS

    JavaMail Gmail Error !! Strucked - "Must issue a STARTTLS command first"

    248
      I have used the code as below. !!

      I guess code is perfect and i have tried many alternative code. but not working !!

      I am calling the function from my other Page

      Error

      oracle.apps.fnd.framework.OAException: java.lang.RuntimeException: javax.mail.SendFailedException: Sending failed;
      class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first. nh6sm15292366pbc.44

      <h5>
      import java.util.Properties;
      import javax.mail.Message;
      import javax.mail.MessagingException;
      import javax.mail.PasswordAuthentication;
      import javax.mail.Session;
      import javax.mail.Transport;
      import javax.mail.internet.InternetAddress;
      import javax.mail.internet.MimeMessage;

      public class SendMail {
      public static void send(String to, String from, String subject,
      String body) {
      final String username = "emailId";
      final String password = "password";


      Properties props = new Properties();
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.host", "smtp.gmail.com");
      props.put("mail.smtp.port", "587");

      Session session = Session.getInstance(props,
      new javax.mail.Authenticator() {
      protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication(username, password);
      }
      });

      session.setDebug(true);
      try {

      Message message = new MimeMessage(session);
      message.setFrom(new InternetAddress(from));
      message.setRecipients(Message.RecipientType.TO,
      InternetAddress.parse(to));
      message.setSubject(subject);
      message.setText(body);

      Transport.send(message);
      System.out.println("Done");

      }
      catch (MessagingException e)
      {
      throw new RuntimeException(e);
      }

      }

      public static void main(String[] args) {
      SendMail sendMail = new SendMail();

      sendMail.send("shail41@gmail.com", "shail41@gmail.com", "javamail", "Body");

      }
      }
      </h5>

      Edited by: 942767 on Jun 27, 2012 7:14 AM