发送电子邮件在测试中有效,但在生产中无效
我在应用程序中创建了此功能。当我测试它时,它可以很好地工作。当我发布该应用程序时,没有发送电子邮件。有人知道会发生什么吗?
在生产中,代码也有效,并且没有显示任何错误消息。但是,电子邮件未发送。在本地测试环境中,电子邮件非常完美。我相信代码不是问题。我想一些配置使您无法在生产中使用此功能。
我已经对该主题进行了大量研究,但没有找到任何可以帮助的东西。
我正在使用Java Android Studio。
谢谢你!
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 = "[email protected]";
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);
}
}
I created this function in my application. While I'm testing it, it works perfectly. When I publish the App, no emails are sent. Does anyone have any idea what could be happening?
In production the code also works and does not show any error message. However, the email is not sent. In the local test environment, the email is sent perfectly. I believe the code is not the problem. I imagine some configuration is preventing you from using this feature in production.
I've done a lot of research on the subject and haven't found anything that could help.
I am using Android Studio, JAVA.
Thank you!
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 = "[email protected]";
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论