0
votes

I am sending emails from my app, without using email intent. But gmail detecting them as spam and prevent sending.Here is the error delivery report,

Delivery to the following recipient failed permanently:

 [email protected]

Technical details of permanent failure: Message rejected. See http://support.google.com/mail/bin/answer.py?answer=69585 for more information.

----- Original message -----

X-Received: by 10.68.196.164 with SMTP id in4mr16083110pbc.128.1391108875462; Thu, 30 Jan 2014 11:07:55 -0800 (PST) Return-Path: Received: from localhost ([122.166.89.61]) by mx.google.com with ESMTPSA id bz4sm19949383pbb.12.2014.01.30.11.07.53 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Jan 2014 11:07:54 -0800 (PST) Date: Thu, 30 Jan 2014 11:07:54 -0800 (PST) From: Feedback To: "[email protected]" Message-ID: <1121064448.5.1391108870969.JavaMail.javamailuser@localhost> Subject: CASTLE STREET Feedback MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit

And I am using the following code to send email,

 private void sendMail() {
        Session session = createSessionObject();

        try {

            Message[] message=new Message[EMAIL_TITLE.length];






            for(int i=0;i<EMAIL_TITLE.length;i++)

             {

            message[i] = createMessage(EMAIL_TITLE[i], Activity_login.BranchName+" Feedback", "Customer Feedback Received for dining\n\n\n" +
                    "Customer Feedback Received for home delivery\n\n\nOrder No : "+newbill+"\nCustomer Name : "+newname+"\nCustomer Mobile : "+mobile+"\nCall center exec. "+call_cntr+"\nDelivery Boy: "+del_boy+"\nBranch : "+Activity_login.BranchName+"\nFood : "+food+" Star\nAmbiance : "+ambiance+" Star\nService :"+service+" Star\nComments : "+comments.getText().toString(), session);

             }



            new SendMailTask(HDActivityAdmin.this).execute(message);






        } catch (AddressException e) {
            e.printStackTrace();
        } catch (MessagingException e) {
            e.printStackTrace();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    private Message createMessage(String email, String subject, String messageBody, Session session) throws MessagingException, UnsupportedEncodingException {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(Activity_login.Email, "Feedback"));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(email, email));
        message.setSubject(subject);
        message.setText(messageBody);
        return message;
    }

    private Session createSessionObject() {
        Properties properties = new Properties();
        properties.put("mail.smtp.auth", "true");
        properties.put("mail.smtp.starttls.enable", "true");
        properties.put("mail.smtp.host", "smtp.gmail.com");
        properties.put("mail.smtp.port", "587");

        return Session.getInstance(properties, new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("[email protected]", "password");
            }
        });
    }


 private class SendMailTask extends AsyncTask<Message, Void, Void> {
        private ProgressDialog progressDialog;
        private ProgressDialog dialog;
        /** application context. */
        private Activity activity;
        private Context context;


        public SendMailTask(Activity activity) {
            this.activity = activity;

            context = activity;
            dialog = new ProgressDialog(context);
        }


        @Override
        protected void onPreExecute() {
            super.onPreExecute();

          dialog = new ProgressDialog(context);


           this.dialog.setMessage("Sending E-mails, Please wait...");
          this.dialog.show();



        }

        @Override
        protected void onPostExecute(Void aVoid) {
            super.onPostExecute(aVoid);


           if (dialog.isShowing()) {
                dialog.dismiss();
            }


           AlertDialog alertDialog = new AlertDialog.Builder(
                    HDActivityAdmin.this).create();

            alertDialog
                    .setMessage(Output);
            alertDialog.setButton("OK",
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Add your code for the button here.

                            finish();
                        }
                    });
            alertDialog.show();




        }

        @Override
        protected Void doInBackground(Message... messages) {
            try {


                for(int i=0;i<messages.length;i++)
                {

                    Transport.send(messages[i]);

                }




            } catch (MessagingException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
1

1 Answers

0
votes

Spam detection doesn't care what code you use to send the message, it only cares about the content of the message. Make sure your message doesn't look like spam. Does it have a valid From and To address? It looks like your message just has a From address of "Feedback". That's most likely the problem.