我從我的應用程序發送電子郵件,而不使用電子郵件意圖。但Gmail的檢測它們爲垃圾郵件,防止sending.Here被錯誤送達報告,在Android中發送電子郵件
傳遞到下列收件人永久失敗:
[email protected]
永久性故障的技術細節:消息拒絕。有關更多信息,請參閱 http://support.google.com/mail/bin/answer.py?answer=69585。
-----原始消息-----
X-接收:由10.68.196.164與SMTP ID in4mr16083110pbc.128.1391108875462; 2014年1月30日11時07分55秒-0800(PST)返回路徑:收到: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); 2014年1月30日11:07:54 -0800(PST)日期:2014年1月30日星期四11:07:54 -0800(PST)來自:意見反饋至: 「[email protected]」Message-ID: < [email protected]>主題: CASTLE STREET反饋MIME-Version:1.0 Content-Type:text/plain; 的charset = US-ASCII內容傳輸編碼:7位
,我使用下面的代碼來發送電子郵件,
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;
}
}