【发布时间】:2017-05-25 21:40:46
【问题描述】:
我正在处理从我的应用程序发送 gmail 的问题,我有以下代码:
public class Notificator {
public static void main(String[] args) {
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("r","");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from@no-spam.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to@no-spam.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler," +
"\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
我收到以下错误:线程“main”中的异常 java.lang.RuntimeException: javax.mail.AuthenticationFailedException: failed to connect
因此,我启用了安全性较低的设备的访问权限,并在防火墙中启用了 intellij。
编辑:是的,我有正确的凭据,只是在放在这里之前删除了它们。
【问题讨论】:
-
所以你的认证是错误的。你真的有一个空白密码吗?还有一个字母的用户名?
-
不,我只是介绍了我的实际细节。我有正确的,但仍然无法连接。
-
JavaMail 常见问题解答有 tips for debugging connection problems。
-
@BillShannon 已经尝试过,但没有成功。
-
您到底尝试了什么,结果究竟如何? JavaMail 调试输出显示什么?
标签: java gmail jakarta-mail