Hallo,
ich versuche eine Email per Java zu senden, und bekomme eine Exception, zu der ich auch nach längerem Googeln nichts gefunden habe:
javax.mail.MessagingException: 554 5.5.1 This session already uses TLS {mp018}
at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:2023)
at com.sun.mail.smtp.SMTPTransport.startTLS(SMTPTransport.java:1872)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:648)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
at meinProgramm.SendMail.(SendMail.java:47)
at meinProgramm.Main.main(Main.java:21)
Ich versuche auf den GMX-Server zu connecten (mail.gmx.net, port 465), und benutze die neueste version von java mail. Bei Gmx ist „SMTP mit Login“ aktiviert.
Code:
public class SendMail {
String d_email = „******@gmx.at“,
d_password = „*******“,
d_host = „mail.gmx.net“,
d_port = „465“,
m_subject = „Testing“,
m_text = „Hey, this is the testing email.“;
public SendMail(String to) throws Exception {
Properties props = new Properties();
props.put(„mail.smtp.user“, d_email);
props.put(„mail.smtp.host“, d_host);
props.put(„mail.smtp.port“, d_port);
props.put(„mail.smtp.starttls.enable“, „true“);
props.put(„mail.smtp.auth“, „true“);
//props.put(„mail.smtp.debug“, „true“);
props.put(„mail.smtp.socketFactory.port“, d_port);
props.put(„mail.smtp.socketFactory.class“, „javax.net.ssl.SSLSocketFactory“);
props.put(„mail.smtp.socketFactory.fallback“, „false“);
try {
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);
MimeMessage msg = new MimeMessage(session);
msg.setText(m_text);
msg.setSubject(m_subject);
msg.setFrom(new InternetAddress(d_email));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
Transport.send(msg);
} catch (Exception mex) {
mex.printStackTrace();
}
}
private class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(d_email, d_password);
}
}
Danke für die Hilfe!