javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first k1sm7539039ugf.29
Buscando por ahi dicen que es porque me podria faltar:
props.setProperty("mail.smtp.starttls.enable","tru e");
pero yo lo tengo incluido en el codigo.
He probado con autenticacion y sin ella y siempre me da el mismo error.
Pondre la traza que escribe en consola:
DEBUG: setDebug: JavaMail version 1.3.1
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587
220 mx.google.com ESMTP k1sm7539039ugf.29
DEBUG SMTP: connected to host "smtp.gmail.com", port: 587
EHLO cristina
250-mx.google.com at your service, [88.9.102.148]
250-SIZE 28311552
250-8BITMIME
250-STARTTLS
250 ENHANCEDSTATUSCODES
DEBUG SMTP: Found extension "SIZE", arg "28311552"
DEBUG SMTP: Found extension "8BITMIME", arg ""
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
DEBUG SMTP: use8bit false
MAIL FROM:<[email protected]>
530 5.7.0 Must issue a STARTTLS command first k1sm7539039ugf.29
QUIT
javax.mail.SendFailedException: Sending failed;
nested exception is:
class javax.mail.MessagingException: 530 5.7.0 Must issue a STARTTLS command first k1sm7539039ugf.29
at javax.mail.Transport.send0(Transport.java:218)
at javax.mail.Transport.send(Transport.java:80)
at pa.envioCorreo(pa.java:65)
at pa.main(pa.java:14)
y ahora el codigo:
Código PHP:
public static void envioCorreo() {
java.security.Security
.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
Properties props = new Properties();
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.transport.protocol","smtp");
props.setProperty("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
props.setProperty("mail.user", "[email protected]");
props.setProperty("mail.password", "password");
Authenticator auth = new SMTPAuthenticator("cristinahdezs","password");
javax.mail.Session session = javax.mail.Session
.getInstance(props, auth);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
try {
// Quien envia el correo
message.setFrom(new InternetAddress("[email protected]"));
// A quien va dirigido
message.addRecipient(Message.RecipientType.TO, new InternetAddress(
"[email protected]"));
DataHandler dh = new DataHandler("Prueba de envio de mail","text/plain");
message.setDataHandler(dh);
javax.mail.Transport.send(message);
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
}