0
我使用java邮件从服务器发送邮件。我使用下面的代码,但我得到这个错误..显示授权失败的Java邮件
Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException
at mail.mailSSL.main(mailSSL.java:53)
Caused by: javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at javax.mail.Service.connect(Service.java:156)
at javax.mail.Service.connect(Service.java:105)
at javax.mail.Transport.send0(Transport.java:168)
at javax.mail.Transport.send(Transport.java:98)
at mail.mailSSL.main(mailSSL.java:48)
我的代码:
public class mailSSL {
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("[email protected]","[email protected]");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("[email protected]"));
message.setSubject("SFTS MAIL TESING");
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);
}
}
}
我怎样才能解决这个问题?
你可能想要在上面的帖子中用“*”来编辑和替换你的密码。您是否尝试过简单而简单的mail.smtp.user或mail.smtp.password? – aishwarya