Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
自动脚本失败时使用Mailtrap发送电子邮件(Selenium-Java)_Java_Selenium Webdriver_Jakarta Mail_Mailtrap - Fatal编程技术网

自动脚本失败时使用Mailtrap发送电子邮件(Selenium-Java)

自动脚本失败时使用Mailtrap发送电子邮件(Selenium-Java),java,selenium-webdriver,jakarta-mail,mailtrap,Java,Selenium Webdriver,Jakarta Mail,Mailtrap,Hi community:我尝试在特定脚本失败时自动发送电子邮件(使用Mailtrap而不是Gmail) 下面是下一个错误: javax.mail.AuthenticationFailedException: 535 5.7.0 Invalid login or password 我知道密码和用户名都可以,没有空格 这些是我在POM中的依赖项 <dependency> <groupId>javax.mail</groupId>

Hi community:我尝试在特定脚本失败时自动发送电子邮件(使用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>

javax.mail
javax.mail-api
1.6.2
com.sun.mail
javax.mail
1.6.2
这是我发送电子邮件的课程:

    public class SendEmail {

    public static final String SMTP_HOST_NAME = "smtp.mailtrap.io";
    public static final String SMTP_AUTH_USER = "xxxxxxx@xxxxxx.com";
    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 = "noreply@mailtrap.io";

    // Add List of Email address where user wish to send the email
    public static final String[] emailList = {"xxxxxxxxx@gmail.com"};

    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\u HOST\u NAME=“SMTP.mailtrap.io”;
公共静态最终字符串SMTP\U AUTH\U USER=”xxxxxxx@xxxxxx.com";
公共静态最终字符串SMTP_AUTH_PWD=“xxxxxxx 2019$”;
公共静态最终字符串SMTP_SF_PORT=“465”;
公共静态最终字符串SMTP_PORT=“2525”;
public static final String emailMsgTxt=“运行测试自动化时发现错误”;
公共静态最终字符串emailSubjectTxt=“来自Selenium WebDriver的错误消息”;
公共静态最终字符串emailFromAddress=”noreply@mailtrap.io";
//添加用户希望发送电子邮件的电子邮件地址列表
公共静态最终字符串[]emailList={”xxxxxxxxx@gmail.com"};
public void postMail(字符串收件人[],字符串主题,
字符串消息,字符串来自)抛出MessaginException
{
布尔调试=假;
//设置主机smtp地址
Properties props=新属性();
props.put(“mail.smtp.host”,smtp\u主机名);
props.put(“mail.smtp.socketFactory.port”,smtp\u SF\u端口);
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\u端口);
Authenticator auth=新的SMTPAuthenticator();
Session Session=Session.getDefaultInstance(props,auth);
setDebug(debug);
//创建消息
Message msg=新的mimessage(会话);
//设置发件人和收件人地址
InternetAddress addressFrom=新的InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[]addressTo=新的InternetAddress[recipients.length];
for(int i=0;i
有人能帮我吗?

凭证有误! 不要使用帐户凭据( 公共静态最终字符串SMTP\U AUTH\U USER=”xxxxxxx@xxxxxx.com“;)您需要收件箱凭据。

非常感谢Tufisi。