TLS-Problem beim senden von gmail über JavaMail

Stellt sich heraus, dass JavaMail ist ein bisschen mehr frustrierend, als ich dachte, es wäre. Ich habe mehrere Beispiele für online -, wie zu senden, eine einfache SMTP-E-Mails über die Server von Gmail (aber nicht über SSL). Nach dem Versuch mehrere andere Beispiele von code, ich halte den Abschluss für das gleiche Beispiel für die Ausnahme, wenn ich rufe transport.connect(). Ich bekomme immer diese stack-trace:

Exception in thread "main" com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.0 Must issue a STARTTLS command first. l10sm302158wfk.21
     at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2057)
     at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1580)
     at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1097)
     at SendEmail.main(SendEmail.java:47)

Kann mir bitte jemand sagen, was ich hinzufügen sollte oder das Problem beheben?

Hier ist mein code:

    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");
    props.put("mail.host", "smtp.gmail.com");
    props.put("mail.user", "[email protected]");
    props.put("mail.password", "blah");
    props.put("mail.port", "587");

    Session mailSession = Session.getDefaultInstance(props, null);
    Transport transport = mailSession.getTransport();

    MimeMessage message = new MimeMessage(mailSession);
    message.setSubject("This is a test");
    message.setContent("This is a test", "text/plain");
    message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

    transport.connect();
    transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
    transport.close();
InformationsquelleAutor Brian | 2011-06-28
Schreibe einen Kommentar