我正在使用javax.mail发送Java中的邮件。 现在,我的项目的一部分概念发生了变化,我必须发送邮件而无需身份验证。我将不得不改变我的了createSession()方法:未经身份验证在javax.mail中发送邮件
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);
}
});
}
这是相当明显的是,我应该改变mail.smtp.auth
到false
,但我还需要改变?
不要把'user'和'password'加到''属性'上,''把用户'和'密码'''连接到'' –