0

我正在使用这个示例代码:

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 WebMail 移动/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
4

1 回答 1

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"); 

这可能会有所帮助。

于 2013-01-31T23:29:58.280 回答