I have a method that sends email back ground that works well, but I need to make sure that as the amount of incoming email does not come from Spam. I have already researched the Java Message Service (JMS) framework but I have not found a way to make it work and I have not found an example.
The idea is to call this frame work and pass SMTP into it.
If you can show an example, I'll be grateful.
Remembering that the method works well, but if in the case an email receives more than 10 thousand emails for example, it could go to Spam. That's why I wanted to find a way for it not to happen.
Here is the method I use to send the email back:
ui.btnEnviarPedidoParaEmail.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rec = "";
subject = "Pedido Solicitado";
textMessage = "Nome: " + ui.nome.getText() +
"<br />" + "Rua: " + ui.rua.getText() +
"<br />" + "Número: " + ui.numero.getText() +
"<br />" + "Complemento: " + ui.complemento.getText() +
"<br />" + "Bairro: " + ui.bairro.getText() +
"<br />" + "CEP: " + ui.cep.getText() +
"<br />" + "Telefone: " + ui.telefone1.getText() +
"<br />" + "Celular: " + ui.telefone2.getText() +
"<br />" + "Valor total do Pedido: " + CurrencyUtils.format(BigDecimal.valueOf(valorDoPedido)) +
"<br />" + "-------------------------------" +
"<br />" + "Lista de itens solicitados:" +
"<br />" + "Produto: " + nomeDoProduto +
"<br />" + "Descrição: " + descricaoDoProduto +
"<br />" + "Preço unitário: " + CurrencyUtils.format(BigDecimal.valueOf(precoUnitarioDoProduto)) +
"<br />" + "Quantidade :" + quantidadeDoProduto;
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
session = Session.getDefaultInstance(props, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("", "");
}
});
pdialog = ProgressDialog.show(context, "", "Enviando o pedido para o email...", true);
RetreiveFeedTask task = new RetreiveFeedTask();
task.execute();
}
class RetreiveFeedTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(""));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(rec));
message.setSubject(subject);
message.setContent(textMessage, "text/html; charset=utf-8");
Transport.send(message);
} catch (MessagingException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
pdialog.dismiss();
Toast.makeText(getApplicationContext(), "Pedido enviado com sucesso!", Toast.LENGTH_SHORT).show();
}
}
});