我正在使用SMTP錯誤發送電子郵件。我正在驗證不成功。用戶名和密碼是正確的。難道我做錯了什麼。javax.mail.AuthenticationFailedException:535 5.7.3身份驗證失敗
錯誤日誌
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class EmailSender{
public static void main(String args[]) {
String to = "[email protected]"; // sender email
String from = "[email protected]"; // receiver email
String host = "dkdkdd.xxx.com"; // mail server host
String login="dkkdkd";
String pass="dkkdkd";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.smtp.user", login);
properties.setProperty("mail.smtp.password", pass);
properties.setProperty("mail.smtps.ssl.enable", "true");
// properties.setProperty("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(properties); // default session
try {
MimeMessage message = new MimeMessage(session); // email message
message.setFrom(new InternetAddress(from)); // setting header fields
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Test Mail from Java Program"); // subject line
// actual mail body
message.setText("You can send mail from Java program by using");
// Send message
Transport transport = session.getTransport("smtp");
transport.connect(host, login, pass);
Transport.send(message);
System.out.println("Email Sent successfully....");
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}
的錯誤是
DEBUG SMTP:AUTH NTLM螺紋失敗 異常 「主要」 javax.mail.AuthenticationFailedException:535 5.7.3身份驗證不成功
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)
我已經試過這個,並且我得到了同樣的錯誤ie異常在線程「main」javax.mail.AuthenticationFailedException:535 5.7.3身份驗證失敗 –
再次將auth設置爲true ... @ MukeshKumar並添加 道具。 setProperty(「mail.smtp.starttls.enable」,「true」); –
非常感謝您的提示回覆。我添加了你提到的內容。我得到錯誤220 2.0.0 SMTP服務器準備好 線程「main」中的異常javax.mail.MessagingException:無法將套接字轉換爲TLS;嵌套的異常是:javax.net.ssl.SSLHandshakeException:sun.security.validator.ValidatorException:PKIX路徑構建失敗:sun.security.provider.certpath.SunCertPathBuilderException:無法找到com.sun.mail中所請求的目標的有效證書路徑.smtp.SMTPTransport.startTLS(SMTPTransport.java:1907)at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:666) –