为什么我得到一个空的javax.mail.AuthenticationFailedException?

时间:2014-10-13 16:21:20

标签: email exception authentication javamail javax.mail

我正在制作一个自动发送电子邮件的网络应用,所以我使用的是javamail。我需要使用我公司的SMPT,无论我做什么,我都会得到一个nulljavax.mail.AuthenticationFailedException。这是我第一次使用它而且我真的很沮丧,因为我尝试了大量的解决方案,但我仍然无法弄清楚错误是什么。我使用gmail进行了测试并且它有效,但到目前为止没有任何帮助。这是我的代码:

更新:我对代码进行了更改,并按照建议删除了身份验证器。

     final String username = "dva.clamadrid@grupoautofin.com";
            final String password = "Leprechaun01";

            Properties props = new Properties();


            props.put("mail.transport.protocol", "smtp");

            props.put("mail.smtp.auth", "true");



            Session session = Session.getInstance(props);



            try {
                session.setDebug(true);
                Message message = new MimeMessage(session);
                message.setFrom(new InternetAddress("dva.clamadrid@grupoautofin.com"));
                message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse("dva.clamadrid@grupoautofin.com"));
                message.setRecipients(Message.RecipientType.CC,
                        InternetAddress.parse(Copy));
                message.setSubject("Testing Subject");
                message.setText("Dear Mail Crawler,"
                    + "\n\n No spam to my email, please!");

                Transport transport = session.getTransport("smtp");
                transport.connect("SMTP.grupoautofin.com", 25, username, password);
                transport.sendMessage(message, message.getAllRecipients());
                transport.close();

                Log.i("Estás enviando: ",""+message.toString());

                System.out.println("Done");

            }catch(AuthenticationFailedException e) {
                    Log.e("ERROR DE AUTENTIFICACION: ",""+e.getMessage()+e);
                    e.printStackTrace();
                 bandera = false;

            } catch (MessagingException e) {
                bandera=false;
                Log.e("ERROR ENVIANDO: ",""+e.getMessage()+e);

                e.printStackTrace();

                //throw new RuntimeException(e);
            }

此外,我的错误日志,现在有调试消息:

10-13 15:56:13.504: I/System.out(802): DEBUG: setDebug: JavaMail version 1.4.1
10-13 15:56:13.544: I/System.out(802): DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1]
10-13 15:56:13.544: I/System.out(802): DEBUG SMTP: useEhlo true, useAuth true
10-13 15:56:13.544: I/System.out(802): DEBUG SMTP: trying to connect to host "SMTP.grupoautofin.com", port 25, isSSL false
10-13 15:56:13.835: I/System.out(802): 220 mtysmtp01.mexico.hosting.triara SMTP Server 01 is ready. Mon, 13 Oct 2014 14:56:13 -0500 
10-13 15:56:13.845: I/System.out(802): DEBUG SMTP: connected to host "SMTP.grupoautofin.com", port: 25
10-13 15:56:13.855: I/System.out(802): EHLO localhost
10-13 15:56:13.905: I/System.out(802): 250-mtysmtp01.mexico.hosting.triara Hello [189.203.255.42]
10-13 15:56:13.905: I/System.out(802): 250-TURN
10-13 15:56:13.905: I/System.out(802): 250-SIZE 27262976
10-13 15:56:13.915: I/System.out(802): 250-ETRN
10-13 15:56:13.915: I/System.out(802): 250-PIPELINING
10-13 15:56:13.915: I/System.out(802): 250-DSN
10-13 15:56:13.915: I/System.out(802): 250-ENHANCEDSTATUSCODES
10-13 15:56:13.915: I/System.out(802): 250-8bitmime
10-13 15:56:13.915: I/System.out(802): 250-BINARYMIME
10-13 15:56:13.915: I/System.out(802): 250-CHUNKING
10-13 15:56:13.915: I/System.out(802): 250-VRFY
10-13 15:56:13.915: I/System.out(802): 250-X-EXPS GSSAPI NTLM LOGIN
10-13 15:56:13.915: I/System.out(802): 250-X-EXPS=LOGIN
10-13 15:56:13.925: I/System.out(802): 250-AUTH GSSAPI NTLM LOGIN
10-13 15:56:13.925: I/System.out(802): 250-AUTH=LOGIN
10-13 15:56:13.925: I/System.out(802): 250-X-LINK2STATE
10-13 15:56:13.925: I/System.out(802): 250-XEXCH50
10-13 15:56:13.925: I/System.out(802): 250 OK
10-13 15:56:13.935: I/System.out(802): DEBUG SMTP: Found extension "TURN", arg ""
10-13 15:56:13.935: I/System.out(802): DEBUG SMTP: Found extension "SIZE", arg "27262976"
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "ETRN", arg ""
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "PIPELINING", arg ""
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "DSN", arg ""
10-13 15:56:13.945: I/System.out(802): DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
10-13 15:56:13.955: I/System.out(802): DEBUG SMTP: Found extension "8bitmime", arg ""
10-13 15:56:13.955: I/System.out(802): DEBUG SMTP: Found extension "BINARYMIME", arg ""
10-13 15:56:13.955: I/System.out(802): DEBUG SMTP: Found extension "CHUNKING", arg ""
10-13 15:56:13.965: I/System.out(802): DEBUG SMTP: Found extension "VRFY", arg ""
10-13 15:56:13.965: I/System.out(802): DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
10-13 15:56:13.965: I/System.out(802): DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
10-13 15:56:13.975: I/System.out(802): DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
10-13 15:56:13.975: I/System.out(802): DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
10-13 15:56:13.985: I/System.out(802): DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
10-13 15:56:14.004: I/System.out(802): DEBUG SMTP: Found extension "XEXCH50", arg ""
10-13 15:56:14.004: I/System.out(802): DEBUG SMTP: Found extension "OK", arg ""
10-13 15:56:14.015: I/System.out(802): DEBUG SMTP: Attempt to authenticate
10-13 15:56:14.025: I/System.out(802): AUTH LOGIN
10-13 15:56:14.075: I/System.out(802): 334 VXNlcm5hbWU6
10-13 15:56:14.085: I/System.out(802): ZHZhLmNsYW1hZHJpZEBncnVwb2F1dG9maW4uY29t
10-13 15:56:14.135: I/System.out(802): 334 UGFzc3dvcmQ6
10-13 15:56:14.135: I/System.out(802): TGVwcmVjaGF1bjAx
10-13 15:56:14.416: I/System.out(802): 535 5.7.3 Authentication unsuccessful.
10-13 15:56:14.424: E/ERROR DE AUTENTIFICACION:(802): nulljavax.mail.AuthenticationFailedException

仍然得到同样的错误,我还有什么不对的?提前谢谢。

1 个答案:

答案 0 :(得分:0)

首先,you don't need the Authenticator,摆脱它。

其次,如果您要明确调用connect方法,那么您就不需要主机,端口或身份验证属性,因此您也可以删除它们。

您已经做了一些事情来验证您是否传递了正确的用户名和密码,对吗?

启用session debugging,调试输出可能会提供更多关于出错的线索。您可能需要设置" mail.debug.auth"财产到"真"查看完整的身份验证协议交换(包括您的密码)以查看失败的详细信息。如果仍然无法解决问题,请发布调试输出(不进行身份验证交换)。