我在应用程序中创建了此函数。当我测试它时,它工作得很好。当我发布应用程序时,不会发送电子邮件。有人知道会发生什么吗?
在生产中,该代码也可以工作,不会显示任何错误消息。但是,不会发送电子邮件。在本地测试环境中,电子邮件可以完美地发送。我相信代码不是问题所在。我想某些配置会阻止您在生产中使用此功能。
我在这个问题上做了很多研究,没有发现任何有用的东西。
我正在使用Android Studio,JAVA。
非常感谢。
private void enviaEmailBoasVindas() {
Connection ipp_CON_CONNEC;
String Mail_Username = "";
String Mail_Password = "";
String Mail_Destino = "";
String Mail_Copia = "";
String Mail_Message = "TESTE";
Mail_Message = Mail_Message.replace("[USERNAME]", iPPData.getNomeCompleto().toString().trim());
try {
ipp_CON_CONNEC = iPPdb.AbreConexao();
if (ipp_CON_CONNEC != null) {
String ipp_STR_SQLQRY = "myquery";
if (ipp_RES_DATSET.next()) {
do {
Mail_Username = ipp_RES_DATSET.getString("tbdata1").toString().trim();
Mail_Password = ipp_RES_DATSET.getString("tbdata2").toString().trim();
} while (ipp_RES_DATSET.next());
}
ipp_CON_CONNEC.close();
}
} catch (SQLException throwables) {
String erro = throwables.getMessage();
}
Mail_Destino = iPPData.getUserEmail();
Mail_Copia = "xxxxxxxxx@gmail.com";
Properties props = new Properties();
props.put("mail.smtp.auth", true);
props.put("mail.smtp.starttls.enable", true);
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.port", "587");
String finalMail_Username = Mail_Username;
String finalMail_Password = Mail_Password;
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(finalMail_Username, finalMail_Password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(Mail_Username));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(Mail_Destino));
message.setRecipients(Message.RecipientType.BCC, InternetAddress.parse(Mail_Copia));
message.setSubject("xxxxxxxxxxxx");
message.setText(Mail_Message);
Transport.send(message);
} catch (MessagingException e) {
// error
}
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Statement ipp_STA_SQLSTA;
ResultSet ipp_RES_DATSET;
String ipp_STR_SQLQRY = "";
String currentTime = new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date());
String tTitulo = "title";
String tTexto = "text";
try {
ipp_STR_SQLQRY = "myquery";
ipp_CON_CONNEC = iPPdb.AbreConexao();
ipp_STA_SQLSTA = ipp_CON_CONNEC.createStatement();
ipp_STA_SQLSTA.execute(ipp_STR_SQLQRY);
} catch (Exception e) {
SetMessage("Erro Complemento", e.toString() + " / " + ipp_STR_SQLQRY);
}
}