I am using javax.mail to send mails in Java.
Now that a part of the concept of my project changed I have to send a mail without authentication. I will have to change my createSession() method:
private void createSession() {
properties.put("mail.smtp.auth", "true");
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", server);
properties.put("mail.smtp.port", port);
session = Session.getInstance(properties, new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
}
It is rather obvious that I should change mail.smtp.auth
to false
, but what else should I change?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…