【问题标题】:E-mail sending in Android在 Android 中发送电子邮件
【发布时间】:2014-02-23 07:18:16
【问题描述】:

我正在从我的应用程序发送电子邮件,而不使用电子邮件意图。但是 gmail 将它们检测为垃圾邮件并阻止发送。这是错误传递报告,

向以下收件人的递送永久失败:

 customer@abc.in

永久失败的技术细节:消息被拒绝。看 http://support.google.com/mail/bin/answer.py?answer=69585 了解更多 信息。

----- 原始消息-----

X-Received:由 10.68.196.164 发送,带有 SMTP id in4mr16083110pbc.128.1391108875462; Thu, 30 Jan 2014 11:07:55 -0800 (PST) Return-Path: Received: from localhost ([122.166.89.61]) 通过 mx.google.com 与 ESMTPSA id bz4sm19949383pbb.12.2014.01.30.11.07.53 为了 (版本=TLSv1 密码=ECDHE-RSA-RC4-SHA 位=128/128); 2014 年 1 月 30 日星期四 11:07:54 -0800(太平洋标准时间) 日期:2014 年 1 月 30 日星期四 11:07:54 -0800(太平洋标准时间)发件人: 反馈至: "customer@abc.in" 消息 ID: 主题: CASTLE STREET 反馈 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit

我正在使用以下代码发送电子邮件,

 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("feedback@abc.in", "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;
        }
    }

【问题讨论】:

    标签: android email gmail jakarta-mail


    【解决方案1】:

    垃圾邮件检测不关心您使用什么代码发送邮件,它只关心邮件的内容。确保您的邮件看起来不像垃圾邮件。它有有效的 From 和 To 地址吗?看起来您的消息只有“反馈”的发件人地址。这很可能是问题所在。

    【讨论】:

      猜你喜欢
      • 2012-01-21
      • 2013-04-03
      • 1970-01-01
      • 2016-12-20
      • 2017-10-17
      • 2014-02-01
      • 1970-01-01
      相关资源
      最近更新 更多