我正在使用此示例代码:
http://www.jondev.net/articles/Sending_Emails_without_User_Intervention_%28no_Intents%29_in_Android
我正在尝试使用自己的服务器电子邮件来发送电子邮件,而不是专注于Android。
我知道该示例配置为仅适用于Gmail。
我改变了:
_host = "smtp.myserver.com"; // default smtp server
_port = "587"; // default smtp port
_sport = "587"; // default socketfactory port
,这在MainActivity上:
Mail m = new Mail("username@myserver.com", "password"); //to my sever email
我只是在Outlook上设置了正确的信息,它可以工作,我可以通过这封电子邮件发送和接收。
服务器允许此设置:
POP3 SMTP IMAP 邮局 移动/ PDA
问题:
我需要添加/更改更多内容吗?或者此示例无法与其他gmail一起使用。
我在Logcat上遇到了这个错误:
01-31 21:07:08.989: E/MailApp(17094): Could not send email
01-31 21:07:08.989: E/MailApp(17094): javax.mail.MessagingException: Could not connect to SMTP host: smtp.semhora.com, port: 587;
01-31 21:07:08.989: E/MailApp(17094): nested exception is:
01-31 21:07:08.989: E/MailApp(17094): javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x1e4490: Failure in SSL library, usually a protocol error
01-31 21:07:08.989: E/MailApp(17094): error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol (external/openssl/ssl/s23_clnt.c:683 0xad12957d:0x00000000)
01-31 21:07:08.989: E/MailApp(17094): at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1391)
01-31 21:07:08.989: E/MailApp(17094): at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
01-31 21:07:08.989: E/MailApp(17094): at javax.mail.Service.connect(Service.java:310)
01-31 21:07:08.989: E/MailApp(17094): at javax.mail.Service.connect(Service.java:169)
01-31 21:07:08.989: E/MailApp(17094): at javax.mail.Service.connect(Service.java:118)
01-31 21:07:08.989: E/MailApp(17094): at javax.mail.Transport.send0(Transport.java:188)
01-31 21:07:08.989: E/MailApp(17094): at javax.mail.Transport.send(Transport.java:118)
01-31 21:07:08.989: E/MailApp(17094): at com.example.sendemailtester.Mail.send(Mail.java:102)
01-31 21:07:08.989: E/MailApp(17094): at com.example.sendemailtester.MainActivity$1.onClick(MainActivity.java:33)
01-31 21:07:08.989: E/MailApp(17094): at android.view.View.performClick(View.java:2485)
01-31 21:07:08.989: E/MailApp(17094): at android.view.View$PerformClick.run(View.java:9080)
01-31 21:07:08.989: E/MailApp(17094): at android.os.Handler.handleCallback(Handler.java:587)
01-31 21:07:08.989: E/MailApp(17094): at android.os.Handler.dispatchMessage(Handler.java:92)
01-31 21:07:08.989: E/MailApp(17094): at android.os.Looper.loop(Looper.java:130)
01-31 21:07:08.989: E/MailApp(17094): at android.app.ActivityThread.main(ActivityThread.java:3687)
01-31 21:07:08.989: E/MailApp(17094): at java.lang.reflect.Method.invokeNative(Native Method)
01-31 21:07:08.989: E/MailApp(17094): at java.lang.reflect.Method.invoke(Method.java:507)
01-31 21:07:08.989: E/MailApp(17094): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
01-31 21:07:08.989: E/MailApp(17094): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
01-31 21:07:08.989: E/MailApp(17094): at dalvik.system.NativeStart.main(Native Method)
01-31 21:07:08.989: E/MailApp(17094): Caused by: javax.net.ssl.SSLProtocolException: SSL handshake aborted: ssl=0x1e4490: Failure in SSL library, usually a protocol error
答案 0 :(得分:3)
我从来没有使用过这个包装器,但代码假设SSL支持,而你的端口587服务器似乎不支持SSL。注释掉这两行
props.put("mail.smtp.socketFactory.port", _sport);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
并将此行设置为false为true
props.put("mail.smtp.socketFactory.fallback", "false");
这可能有所帮助。