Ich habe folgende Klasse geschrieben, um ein Email zu schicken.
Leider kommt beim Ausführen die Meldung:
........
DEBUG SMTP: need username and password for authetication
DEBUG SMTP: protocolConnect returning false, host=****, user=****, password=(null)
.....
Das verstehe ich nicht. Ich übergebe ja das "user" und "pass" an den PasswordAuthentication.
Vielen Dank für einen Hint
Tony
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.Authenticator;
import javax.mail.internet.*;
public class SendMail {
public static void send(String to, String sub, String msg, final String user, final String pass) {
//create an instance of Properties Class
Properties props = new Properties();
props.put("mail.smtp.host", "****");
// below mentioned mail.smtp.port is optional
props.put("mail.smtp.port", "465");
props.put("mail.smtp.auth", "true");
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.ssl.protocols", "TLSv1.2");
props.put("mail.debug", "true");
props.put("mail.smtp.user", "****");
props.put("mail.smtp.timeout", "5000");
Session session = Session.getInstance(props,new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user,pass);
}
});
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(user));
message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
message.setSubject(sub);
message.setText(msg);
Transport.send(message);
}
catch(Exception e) { e.printStackTrace(); }
}
}
Leider kommt beim Ausführen die Meldung:
........
DEBUG SMTP: need username and password for authetication
DEBUG SMTP: protocolConnect returning false, host=****, user=****, password=(null)
.....
Das verstehe ich nicht. Ich übergebe ja das "user" und "pass" an den PasswordAuthentication.
Vielen Dank für einen Hint
Tony