社区大家好:当特定脚本失败时,我尝试自动执行电子邮件操作(使用Mailtrap而不是Gmail)
我收到下面的下一个错误:
javax.mail.AuthenticationFailedException: 535 5.7.0 Invalid login or password
我知道密码和用户名都可以,并且没有空格。
这些是我对POM的依赖。
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.6.2</version>
</dependency>
这是我发送电子邮件的课程:
public class SendEmail {
public static final String SMTP_HOST_NAME = "smtp.mailtrap.io";
public static final String SMTP_AUTH_USER = "[email protected]";
public static final String SMTP_AUTH_PWD = "xxxxxxx2019$";
public static final String SMTP_SF_PORT = "465";
public static final String SMTP_PORT = "2525";
public static final String emailMsgTxt = "Error found while running Test Automation";
public static final String emailSubjectTxt = "Error Message From Selenium WebDriver";
public static final String emailFromAddress = "[email protected]";
// Add List of Email address where user wish to send the email
public static final String[] emailList = {"[email protected]"};
public void postMail( String recipients[ ], String subject,
String message , String from) throws MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.socketFactory.port", SMTP_SF_PORT);
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", SMTP_PORT);
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getDefaultInstance(props, auth);
session.setDebug(debug);
// create a message
Message msg = new MimeMessage(session);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++)
{
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
System.out.println("Successfully Sent mail to All Users");
}
/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String username = SMTP_AUTH_USER;
String password = SMTP_AUTH_PWD;
return new PasswordAuthentication(username, password);
}
}
}
有人可以帮我吗?
凭证错误!不要使用帐户凭据(公共静态最终字符串SMTP_AUTH_USER =“ [email protected]”;),您需要收件箱凭据。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句