[英]Javax.mail package didn't work in release mode apk
I'm using javax.mail package for mail sending, while application in debug mode it's work fine and send every mail to my account, but when i create release application mail stop sending form application. 我使用javax.mail软件包进行邮件发送,而应用程序处于调试模式,则可以正常工作并将每封邮件发送到我的帐户,但是当我创建发布应用程序邮件时,将停止发送表单应用程序。 code is as given below: 代码如下:
Properties props = new Properties();
props.put("mail.smtp.user", "abc@xyz.com");
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.debug", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
//Creating a new session
session = Session.getDefaultInstance(props, new javax.mail.Authenticator() {
//Authenticating the password
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("abc@xyz.com", "password@123");
}
});
try {
//Creating MimeMessage object
MimeMessage mm = new MimeMessage(session);
//Setting sender address
mm.setFrom(new InternetAddress("abc@xyz.com"));
//Adding receiver
mm.addRecipient(Message.RecipientType.TO, new InternetAddress("abc@xyz.com"));
//Adding subject
mm.setSubject(subject);
//Adding message
mm.setText(message);
//Sending email
Transport.send(mm);
} catch (MessagingException e) {
e.printStackTrace();
}
Generally this problem happen because of proguard, If you add proguard into your project it'll stop some of functionality like this. 通常,由于proguard会发生此问题。如果将proguard添加到项目中,它将停止某些功能。
I did it by adding package javax in proguard-rules.pro file. 我是通过在proguard-rules.pro文件中添加javax软件包来实现的。
-keep class javax.** {*;} -keep类javax。** {*;}
this will add all javax methods's permission in proguard. 这将在proguard中添加所有javax方法的权限。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.