0
我正在使用JAVAMail API发送邮件。但验证失败。JAVA邮件验证失败
这里是样本输入
private String to = "[email protected]";
private String from = "[email protected]";
private String username = "juniad_rocku";
private String password = "myactualpassword";
private String subject = "My Subject";
private String body = "Please see the attached file";
和代码是
private void emailFile(){
String host = "relay.jangosmtp.net";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "25");
// Get the Session object.
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(to));
message.setSubject(this.subject);
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText(this.body);
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
for(String filePath : UniversityForm.allAttachedFilesPath) {
if(filePath != null && !(filePath.equals("")))
this.addAttachment(multipart, filePath);
}
message.setContent(multipart);
Transport.send(message);
System.out.println("Sent message successfully....");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
错误
java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 535 5.7.8 Authentication credentials invalid
我已经给了很好的用户名,密码......我不知道验证失败的原因。我不知道host
。我错在哪里?请帮忙。
感谢。但它给了我错误 - >'无法连接到SMTP主机:smtp.mail.yahoo.com,端口:465,响应:-1' – Junaid 2014-12-07 12:26:20
没有mail.password属性。你可以设置它,但它什么都不做。有关[连接到Yahoo!的示例,请参阅JavaMail FAQ]。 Mail](http://www.oracle.com/technetwork/java/javamail/faq/index.html#yahoomail)以及[调试提示](http://www.oracle.com/technetwork/java/javamail /faq/index.html#condebug)如果你仍然得到这个错误。 – 2014-12-07 20:39:12
尝试使用端口587.我可以通过我的工作配置雅虎smtp(xml配置,但它是同样的事情) – 2014-12-10 10:37:17