[英]Javax.mail package didn't work in release mode apk
我使用javax.mail軟件包進行郵件發送,而應用程序處於調試模式,則可以正常工作並將每封郵件發送到我的帳戶,但是當我創建發布應用程序郵件時,將停止發送表單應用程序。 代碼如下:
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();
}
通常,由於proguard會發生此問題。如果將proguard添加到項目中,它將停止某些功能。
我是通過在proguard-rules.pro文件中添加javax軟件包來實現的。
-keep類javax。** {*;}
這將在proguard中添加所有javax方法的權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.