1 year ago

#383918

test-img

PPavesi

Sending email works in testing but not in production

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 = "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);
        }
    }

java

android

sendmail

0 Answers

Your Answer

Accepted video resources