我刚刚发现我需要的用户有一个System.Net.NetworkCredential,javamail中是否有任何属性或类似内容?我问,因为我刚刚检查了我使用它的代码,但它是用C#编写的,我不知道如何将它放在javamail上...
这是我的代码片段:
final String username = "myaccount@mydomain.com";
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("senderadress@mydomain.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("myadress@mydomain.com"));
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();
}
我的调试日志,我收到响应代码454,响应:454 5.7.3客户端无权向此服务器提交邮件:
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:<notificaciones@grupoautofin.com>
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]
答案 0 :(得分:0)
我不知道那是什么。
但是,看起来您的服务器不支持STARTTLS。您可能需要首先建立SSL连接。摆脱“25”的所有用途,并将“mail.smtp.ssl.enable”设置为“true”。
删除mail.smtp.auth设置,并更改connect调用以指定用户名和密码。
upgrade your version of JavaMail如果可以的话!
如果仍然无效,请发布新的调试输出。