简体   繁体   English

自动发送电子邮件失败

[英]automated email sending failure

I am using this article to help me send automated emails, but I am having an issue in which nothing seems to be happening and no errors are generated. 我正在使用这篇文章来帮助我发送自动电子邮件,但是我遇到的问题是似乎什么都没有发生并且没有错误产生。

I used AsyncTask but it is not sending the mail at all. 我使用了AsyncTask,但它根本没有发送邮件。

public class Sender extends AsyncTask< Void, Void, Void> { 公共类Sender扩展了AsyncTask <Void,Void,Void> {

  private Exception exception; protected Void doInBackground(String... arg0) { Log.v("aws", "OPEN asa"); Mail m = new Mail("email@email.com", "password"); String[] toArr = {"to@mail.com"}; m.setTo(toArr); m.setFrom("from@gmail.com"); m.setSubject("This is an email sent using my Mail JavaMail wrapper from an >Android device."); m.setBody("Email body."); try { //m.addAttachment("/sdcard/filelocation"); if(m.send()) { Log.v("aws", "OK SENT"); } else { Log.v("aws", "NOT SENT"); } } catch(Exception e) { Log.v("aws", "EXCEPTION . NOT SENT"); } return null; } @Override protected Void doInBackground(Void... arg0) { // TODO Auto-generated method stub return null; } protected void onPostExecute(Void... arg0) { // TODO: check this.exception // TODO: do something with the feed } 

} }

I have used new Sender().execute(); 我用过new Sender().execute(); to execute the task, but nothing is happening and no errors are being thrown. 执行任务,但是什么也没有发生,也没有抛出任何错误。

What am I doing wrong? 我究竟做错了什么?

EDIT 编辑

Code has two doInBackground such that second overridden my working doInBackground 代码有两个doInBackground这样第二个覆盖了我的工作doInBackground

Be careful, you have two doInBackground() methods in your code, and the @Override version is what gets executed by the AsyncTask . 请注意,您的代码中有两个doInBackground()方法,而@Override版本是由AsyncTask执行的。 Just move the code from the wrong doInBackground() version to the right one and delete the wrong one. 只需将代码从错误的doInBackground()版本移至正确的版本,然后删除错误的版本即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM