JavaMail API不支持移动数据,但在Wifi上运行良好
发布时间:2020-12-15 02:16:03 所属栏目:Java 来源:网络整理
导读:我现在处于非常奇怪的境地.有关完整代码,请在此处查看: http://javapapers.com/android/android-email-app-with-gmail-smtp-using-javamail/ 我正在使用此代码发送电子邮件.但问题是未来.在WIFI上使用此方法发送邮件时,我有100%的成功率.但是当我使用移动
我现在处于非常奇怪的境地.有关完整代码,请在此处查看:
http://javapapers.com/android/android-email-app-with-gmail-smtp-using-javamail/
我正在使用此代码发送电子邮件.但问题是未来.在WIFI上使用此方法发送邮件时,我有100%的成功率.但是当我使用移动数据(4G)时,我的成功率约为30%.在某些设备上,它根本不起作用. 4G连接没有问题.它没有波动.它工作正常.我在多台设备上尝试了这种Wi-Fi和移动数据.一切都表明移动数据上的代码存在一些问题. 目前在我的移动数据调试设备上,代码正在运行.因此我现在无法发布logcat.但很多时候它甚至不适用于调试设备.但是现在它正在工作,我无法发布logcat.最有可能的是,这段代码中存在一些问题: try { Transport transport = mailSession.getTransport("smtp"); transport.connect(emailHost,fromEmail,fromPassword); Log.i("GMail","allrecipients: " + emailMessage.getAllRecipients()); transport.sendMessage(emailMessage,emailMessage.getAllRecipients()); transport.close(); Log.i("GMail","Email sent successfully."); }catch (Exception e){ } 在阅读其他人的帖子时,我发现代理设置可能存在一些问题.但是在代码中,我不知道在哪里可以使用Proxy.NoProxy这样的东西.上面的链接中提供了完整的代码.我没有修改过(除了添加我自己的电子邮件和密码). 这是失败的logcat: 08-09 19:29:54.594 9551-9551/com.parassidhu.cdlumaths I/SendMailActivity: Send Button Clicked. 08-09 19:29:54.594 9551-9551/com.parassidhu.cdlumaths I/SendMailActivity: To List: [cdludeubg@gmail.com] 08-09 19:29:54.654 9551-9893/com.parassidhu.cdlumaths I/d: About to instantiate GMail... 08-09 19:29:54.668 9551-9893/com.parassidhu.cdlumaths I/GMail: Mail server properties set. [ 08-09 19:29:54.677 9551: 9893 W/ ] Unable to open '/system/framework/WfdCommon.jar': No such file or directory 08-09 19:29:55.000 9551-9893/com.parassidhu.cdlumaths I/GMail: toEmail: cdludebug@gmail.com 08-09 19:29:55.099 9551-9893/com.parassidhu.cdlumaths I/GMail: Email Message created. 08-09 19:29:58.393 9551-9893/com.parassidhu.cdlumaths I/Error: sendEmail: null 08-09 19:29:58.393 9551-9893/com.parassidhu.cdlumaths I/com.downloadinformer: Mail Sent. 编辑2 08-10 17:44:58.911 32384-32384/com.parassidhu.cdlumaths I/SendMailActivity: Send Button Clicked. 08-10 17:44:58.911 32384-32384/com.parassidhu.cdlumaths I/SendMailActivity: To List: [cdludeubg@gmail.com] 08-10 17:44:58.922 32384-1140/com.parassidhu.cdlumaths I/d: About to instantiate GMail... 08-10 17:44:58.930 32384-1140/com.parassidhu.cdlumaths I/GMail: Mail server properties set. 08-10 17:44:59.027 32384-1140/com.parassidhu.cdlumaths I/GMail: toEmail: cdludebug@gmail.com 08-10 17:44:59.088 32384-1140/com.parassidhu.cdlumaths I/GMail: Email Message created. 08-10 17:44:59.095 32384-1140/com.parassidhu.cdlumaths D/libc-netbsd: [getaddrinfo]: hostname=smtp.gmail.com; servname=(null); cache_mode=(null),netid=0; mark=0 08-10 17:44:59.095 32384-1140/com.parassidhu.cdlumaths D/libc-netbsd: [getaddrinfo]: hostname=smtp.gmail.com; servname=(null); cache_mode=(null),netid=0; mark=0 08-10 17:44:59.208 32384-1140/com.parassidhu.cdlumaths D/libc-netbsd: getaddrinfo: smtp.gmail.com get result from proxy >> 08-10 17:44:59.219 32384-1140/com.parassidhu.cdlumaths I/System.out: [socket][0] connection smtp.gmail.com/2404:6800:4003:c00::6c:587;LocalPort=44496(0) 08-10 17:44:59.219 32384-1140/com.parassidhu.cdlumaths I/System.out: [CDS]connect[smtp.gmail.com/2404:6800:4003:c00::6c:587] tm:90 08-10 17:45:02.079 32384-1140/com.parassidhu.cdlumaths D/libc-netbsd: [getaddrinfo]: hostname=smtp.gmail.com; servname=(null); cache_mode=(null),netid=0; mark=0 08-10 17:45:02.079 32384-1140/com.parassidhu.cdlumaths D/libc-netbsd: [getaddrinfo]: hostname=smtp.gmail.com; servname=(null); cache_mode=(null),netid=0; mark=0 08-10 17:45:02.083 32384-1140/com.parassidhu.cdlumaths D/libc-netbsd: getaddrinfo: smtp.gmail.com get result from proxy >> 08-10 17:45:02.084 32384-1140/com.parassidhu.cdlumaths I/Error: sendEmail: null 解决方法
它必须与您的邮件服务器上的身份验证有关.只是使用默认的Android电子邮件应用程序,我仍然无法通过Mobile Data访问我的电子邮件服务器,它是一个带有奇怪身份验证的旧服务器.仔细检查身份验证设置服务器端.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |