Search code examples
javapermissionsjakarta-mailresponsenetworkcredentials

System.Net.NetworkCredential property in javamail?


I just found out that the user I need has a System.Net.NetworkCredential, is there any property or something similar in javamail? I ask because I just checked a code where I use it, but it's written in C# and I have no idea how to put that on javamail...

Here's my code snip:

final String username = "[email protected]";
                final String password = "XXXXXXXX";

                Properties props = new Properties();

                 props.put("mail.smtp.host", "SMTP.mysmtphost.com");
                    props.put("mail.debug", "false");
                    props.put("mail.smtp.port", "25");
                    props.put("mail.smtp.timeout", "60000");
                    props.put("mail.smtp.auth", "false");
                    props.put("mail.smtp.ssl.enable", "true");
                    props.put("mail.smtp.ssl.trust", "*");

                    Session session = Session.getInstance(props);
                    Message message = new MimeMessage(session);



                try {
                    session.setDebug(true);

                    message.setFrom(new InternetAddress("[email protected]"));
                    message.setRecipients(Message.RecipientType.TO,
                        InternetAddress.parse("[email protected]"));
                    message.setRecipients(Message.RecipientType.CC,
                            InternetAddress.parse(Copy));
                    message.setSubject("CLIENTE INSATISFECHO");
                    message.setText( "Estimados Gerentes: \n "
                            + " El Cliente "
                            + name
                            + " del área de "
                            + Area
                            + ", con factura "
                            + Factura
                            + " ha manifestado estar insatisfecho, en cuanto a "
                            + Descontentos
                            + ". Favor de dar seguimiento en éste momento. \n\n"
                            + "Atentamente\n"
                            +"Dirección de lealtad y Atención a Clientes.");

                    Transport transport = session.getTransport("smtp");
                    transport.connect();
                    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();

                }

My Debug Log, I'm getting a response code 454, with response: 454 5.7.3 Client does not have permission to submit mail to this server:

10-13 19:01:42.584: I/System.out(2509): DEBUG: setDebug: JavaMail version 1.4.1
10-13 19:01:42.624: I/System.out(2509): DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc.,1.4.1]
10-13 19:01:42.635: I/System.out(2509): DEBUG SMTP: useEhlo true, useAuth false
10-13 19:01:42.675: I/System.out(2509): DEBUG SMTP: trying to connect to host "SMTP.grupoautofin.com", port 25, isSSL false
10-13 19:01:42.825: I/System.out(2509): 220 mtysmtp01.mexico.hosting.triara SMTP Server 01 is ready. Mon, 13 Oct 2014 18:01:42 -0500 
10-13 19:01:42.825: I/System.out(2509): DEBUG SMTP: connected to host "SMTP.grupoautofin.com", port: 25
10-13 19:01:42.845: I/System.out(2509): EHLO localhost
10-13 19:01:43.205: I/System.out(2509): 250-mtysmtp01.mexico.hosting.triara Hello [189.203.255.42]
10-13 19:01:43.224: I/System.out(2509): 250-TURN
10-13 19:01:43.224: I/System.out(2509): 250-SIZE 27262976
10-13 19:01:43.224: I/System.out(2509): 250-ETRN
10-13 19:01:43.224: I/System.out(2509): 250-PIPELINING
10-13 19:01:43.224: I/System.out(2509): 250-DSN
10-13 19:01:43.224: I/System.out(2509): 250-ENHANCEDSTATUSCODES
10-13 19:01:43.224: I/System.out(2509): 250-8bitmime
10-13 19:01:43.235: I/System.out(2509): 250-BINARYMIME
10-13 19:01:43.235: I/System.out(2509): 250-CHUNKING
10-13 19:01:43.235: I/System.out(2509): 250-VRFY
10-13 19:01:43.235: I/System.out(2509): 250-X-EXPS GSSAPI NTLM LOGIN
10-13 19:01:43.235: I/System.out(2509): 250-X-EXPS=LOGIN
10-13 19:01:43.235: I/System.out(2509): 250-AUTH GSSAPI NTLM LOGIN
10-13 19:01:43.235: I/System.out(2509): 250-AUTH=LOGIN
10-13 19:01:43.235: I/System.out(2509): 250-X-LINK2STATE
10-13 19:01:43.235: I/System.out(2509): 250-XEXCH50
10-13 19:01:43.235: I/System.out(2509): 250 OK
10-13 19:01:43.255: I/System.out(2509): DEBUG SMTP: Found extension "TURN", arg ""
10-13 19:01:43.255: I/System.out(2509): DEBUG SMTP: Found extension "SIZE", arg "27262976"
10-13 19:01:43.255: I/System.out(2509): DEBUG SMTP: Found extension "ETRN", arg ""
10-13 19:01:43.255: I/System.out(2509): DEBUG SMTP: Found extension "PIPELINING", arg ""
10-13 19:01:43.255: I/System.out(2509): DEBUG SMTP: Found extension "DSN", arg ""
10-13 19:01:43.265: I/System.out(2509): DEBUG SMTP: Found extension "ENHANCEDSTATUSCODES", arg ""
10-13 19:01:43.265: I/System.out(2509): DEBUG SMTP: Found extension "8bitmime", arg ""
10-13 19:01:43.275: I/System.out(2509): DEBUG SMTP: Found extension "BINARYMIME", arg ""
10-13 19:01:43.275: I/System.out(2509): DEBUG SMTP: Found extension "CHUNKING", arg ""
10-13 19:01:43.275: I/System.out(2509): DEBUG SMTP: Found extension "VRFY", arg ""
10-13 19:01:43.285: I/System.out(2509): DEBUG SMTP: Found extension "X-EXPS", arg "GSSAPI NTLM LOGIN"
10-13 19:01:43.285: I/System.out(2509): DEBUG SMTP: Found extension "X-EXPS=LOGIN", arg ""
10-13 19:01:43.295: I/System.out(2509): DEBUG SMTP: Found extension "AUTH", arg "GSSAPI NTLM LOGIN"
10-13 19:01:43.295: I/System.out(2509): DEBUG SMTP: Found extension "AUTH=LOGIN", arg ""
10-13 19:01:43.335: I/System.out(2509): DEBUG SMTP: Found extension "X-LINK2STATE", arg ""
10-13 19:01:43.335: I/System.out(2509): DEBUG SMTP: Found extension "XEXCH50", arg ""
10-13 19:01:43.345: I/System.out(2509): DEBUG SMTP: Found extension "OK", arg ""
10-13 19:01:43.355: I/System.out(2509): DEBUG SMTP: use8bit false
10-13 19:01:43.365: I/System.out(2509): MAIL FROM:<[email protected]>
10-13 19:01:43.424: I/System.out(2509): 454 5.7.3 Client does not have permission to submit mail to this server.
10-13 19:01:43.424: I/System.out(2509): DEBUG SMTP: got response code 454, with response: 454 5.7.3 Client does not have permission to submit mail to this server.
10-13 19:01:43.424: I/System.out(2509): RSET
10-13 19:01:43.424: I/System.out(2509): DEBUG SMTP: EOF: [EOF]
10-13 19:01:43.436: I/System.out(2509): javax.mail.MessagingException: [EOF]
10-13 19:01:43.436: I/System.out(2509):     at com.sun.mail.smtp.SMTPTransport.issueCommand(SMTPTransport.java:1481)
10-13 19:01:43.436: I/System.out(2509):     at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1512)
10-13 19:01:43.436: I/System.out(2509):     at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1054)
10-13 19:01:43.444: I/System.out(2509):     at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:634)
10-13 19:01:43.444: I/System.out(2509):     at com.example.firmaclientes.EmailSender.EnviandoMail(EmailSender.java:94)
10-13 19:01:43.444: I/System.out(2509):     at com.example.firmaclientes.MainActivity$AsyncMAIL.doInBackground(MainActivity.java:694)
10-13 19:01:43.444: I/System.out(2509):     at com.example.firmaclientes.MainActivity$AsyncMAIL.doInBackground(MainActivity.java:1)
10-13 19:01:43.444: I/System.out(2509):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
10-13 19:01:43.444: I/System.out(2509):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
10-13 19:01:43.455: I/System.out(2509):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
10-13 19:01:43.455: I/System.out(2509):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
10-13 19:01:43.455: I/System.out(2509):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
10-13 19:01:43.455: I/System.out(2509):     at java.lang.Thread.run(Thread.java:841)
10-13 19:01:43.465: E/ERROR ENVIANDO:(2509): [EOF]javax.mail.MessagingException: [EOF]

Solution

  • I have no idea what that is.

    But, it looks like your server doesn't support STARTTLS. You may need to make an SSL connection to begin with. Get rid of all the uses of "25" and set "mail.smtp.ssl.enable" to "true".

    Get rid of the mail.smtp.auth setting, and change the connect call to specify the username and password.

    And upgrade your version of JavaMail if you can!

    If that still doesn't work, post the new debug output.