简体   繁体   English

Java邮件在棉花糖及更高版本上失败,但在棒棒糖及更高版本上成功

[英]Java mail fails on Marshmallow and above, but succeeds on Lollipop and below

I build an APP to send a short message through Java mail API with a guide from this . 我建立一个应用程序发送通过Java API邮件的短消息与指导 It works on my android 5.0.2 phone. 它适用于我的android 5.0.2手机。 But when I deploy it on android 6 or higher, it always failed on authentication. 但是,当我将其部署到android 6或更高版本时,它始终无法通过身份验证。 There is no special change for mail setting compared with the guide mentioned above. 与上述指南相比,邮件设置没有特殊更改。 I list some of them for information. 我列出了其中一些信息。

    public MailSender(String user, String password, String mailhost) {
    this.user = user;
    this.password = password;
    Log.i("SMTP_mail", mailhost);

    Properties props = new Properties();
    props.setProperty("mail.transport.protocol", "smtp");
    props.setProperty("mail.host", mailhost);
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "465");
    props.put("mail.smtp.socketFactory.port", "465");
    props.put("mail.password", password);
    props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.socketFactory.class",
            "javax.net.ssl.SSLSocketFactory");
    props.put("mail.smtp.socketFactory.fallback", "false");
    props.setProperty("mail.smtp.quitwait", "false");

    session = Session.getDefaultInstance(props, this);
    session.setDebug(true);
}

Also, I added permissions check at runtime with a new request from API 23. 另外,我在运行时通过API 23的新请求添加了权限检查。

        if (ContextCompat.checkSelfPermission(this, Manifest.permission.INTERNET)
            != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this,
                new String[]{Manifest.permission.INTERNET},
                4);
    }

And AndroidManifest.xml is as following: AndroidManifest.xml如下:

    <uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="android.permission.SEND_SMS" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.MANAGE_OWN_CALLS" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

With help from the guide for debugging JavaMail, I collect the logs for success and failure. 在调试JavaMail指南的帮助下,我收集了成功和失败的日志。
Success on Android 5: 在Android 5上成功:
在此处输入图片说明

And failure on Android 6: 并在Android 6上失败:
在此处输入图片说明

The app code is the same for these two logs except the platforms are different. 除平台不同外,这两个日志的应用程序代码相同。
Also I notice that there are some certificate failure seen on android 6 log, but from stackoverview search, it seems not a big deal. 我也注意到在android 6日志中看到了一些证书失败,但是从stackoverview搜索来看,这似乎没什么大不了的。 I am not sure whether it impact anything. 我不确定它是否会影响任何事情。

E/NativeCrypto: ssl=0x7ba1e98480 cert_verify_callback x509_store_ctx=0x7ba1cfbc98 arg=0x0 ssl=0x7ba1e98480 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA E / NativeCrypto:ssl = 0x7ba1e98480 cert_verify_callback x509_store_ctx = 0x7ba1cfbc98 arg = 0x0 ssl = 0x7ba1e98480 cert_verify_callback调用verifyCertificateChain authMethod = ECDHE_RSA
I/System.out: gba_cipher_suite:TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA I / System.out:gba_cipher_suite:TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA

Could anyone help with this issue? 有人可以解决这个问题吗? It bothers me for several days. 这困扰了我好几天。 Your help is very appreciated. 非常感谢您的帮助。

Add the INTERNET permission to your manifest file. INTERNET权限添加到清单文件中。

You have to add this line: 您必须添加以下行:

<uses-permission android:name="android.permission.INTERNET" /> 

outside the application tag in your AndroidManifest.xml 在AndroidManifest.xml中的应用程序标记之外

Finally, I get the reason why “535 5.7.1 Authentication failed” was reported. 最后,我得到了为什么报告“ 535 5.7.1身份验证失败”的原因。 It is so unexpected because of the pre-installed ime of the device Meizu Note3(m3 note) with Flyme 6.3.0.2A. 意外的是,由于预装了配备Flyme 6.3.0.2A的魅族Note3(m3 note)设备的ime。 After I change to google ime and type password again, the email could work successfully. 在我更改为google ime并再次输入密码后,电子邮件可能会成功运行。 It is so sad for this reason which cost a lot of time to troubleshooting and end with a so tricky tiny point. 出于这个原因,这太可悲了,它花费大量的时间进行故障排除,并以一个棘手的小问题告终。

Thanks for all guys for comments and suggestions for this ticket. 感谢所有对此票的评论和建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 作物功能适用于棉花糖或以上,但不适用于低于棉花糖 - Crop functionality is working on marshmallow or above but do not work below marshmallow java.lang.RuntimeException:在棒棒糖和棉花糖中takePicture失败 - java.lang.RuntimeException: takePicture failed in lollipop and marshmallow javax.mail在棉花糖或更高版本的系统上不起作用 - javax.mail isn't working on Marshmallow or above systems Imageview未显示在棒棒糖和棉花糖上 - Imageview not showing on Lollipop and Marshmallow 棉花糖及以下api显示循环依赖项错误。 相同的布局在棉花糖上也能正常工作 - Marshmallow and below api's showing circular dependencies error. Same layout works fine above marshmallow 从棉花糖及更高版本中的服务启动时,AlarmManager失败 - AlarmManager fails when initiated from a service in Marshmallow and above 在LOLLIPOP以下的设备上找不到类&#39;com.google.firebase.FirebaseOptions&#39;,在Lollipop及更高版本上无法正常工作 - Could not find class 'com.google.firebase.FirebaseOptions' on devices below LOLLIPOP works fine on Lollipop and above 棒棒糖和棉花糖 gps 问题无法获取经度和纬度值,但相同的代码在低于 21 的 api 上工作 - lollipop and marshmallow gps issue not able to fetch longitude and latitude values but same code working on api below 21 在棒棒糖和棉花糖中找不到位置提供者 - No Location Provider Found in Lollipop and Marshmallow 图像旋转在棒棒糖中起作用,但在棉花糖中不起作用 - Image rotation works in lollipop but not in marshmallow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM