[英]automated email sending failure
我正在使用這篇文章來幫助我發送自動電子郵件,但是我遇到的問題是似乎什么都沒有發生並且沒有錯誤產生。
我使用了AsyncTask,但它根本沒有發送郵件。
公共類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 }
}
我用過new Sender().execute();
執行任務,但是什么也沒有發生,也沒有拋出任何錯誤。
我究竟做錯了什么?
編輯
代碼有兩個doInBackground
這樣第二個覆蓋了我的工作doInBackground
請注意,您的代碼中有兩個doInBackground()
方法,而@Override
版本是由AsyncTask
執行的。 只需將代碼從錯誤的doInBackground()
版本移至正確的版本,然后刪除錯誤的版本即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.