muf*_*fin 26 java email authentication jakarta-mail javax.mail
我使用javax.mail在Java中发送邮件.既然我的项目概念的一部分发生了变化,我必须发送邮件而不进行身份验证.我将不得不改变我的createSession()方法:
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);
}
});
}
Run Code Online (Sandbox Code Playgroud)
这是相当明显的是,我应该换mail.smtp.auth到false,但我还需要改变?
Kri*_*ris 21
private void createSession() {
properties.put("mail.smtp.auth", "false");
//Put below to false, if no https is needed
properties.put("mail.smtp.starttls.enable", "true");
properties.put("mail.smtp.host", server);
properties.put("mail.smtp.port", port);
session = Session.getInstance(properties);
}
Run Code Online (Sandbox Code Playgroud)
我想,这就足够了.