【问题标题】:Android: How to confirm that email has been sent successfullyAndroid:如何确认电子邮件已成功发送
【发布时间】:2013-11-20 07:42:59
【问题描述】:

这是我能够成功发送电子邮件的代码

package com.send.email;    

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {

Button send;

EditText address, subject, emailtext;
/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

send = (Button) findViewById(R.id.emailsendbutton);

address = (EditText) findViewById(R.id.emailaddress);

 subject = (EditText) findViewById(R.id.emailsubject);

 emailtext = (EditText) findViewById(R.id.emailtext);

send.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

// TODO Auto-generated method stub


final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);

emailIntent.setType("image/png");

emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { address.getText().toString() });

emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject.getText());

emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, emailtext.getText());

MainActivity.this.startActivity(Intent.createChooser(emailIntent,"Send mail..."));

}

});
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{

if(requestCode==1)
{
   if(requestCode==1 && resultCode==Activity.RESULT_OK)    
   {
       Toast.makeText(this, "Mail sent.", Toast.LENGTH_SHORT).show();


   }
   else if (requestCode==1 && resultCode==Activity.RESULT_CANCELED)
   {
       Toast.makeText(this, "Mail canceled.", Toast.LENGTH_SHORT).show();


   }
   else 
   {
       Toast.makeText(this, "Plz try again.", Toast.LENGTH_SHORT).show();

   }

}   
}
}

我想找回一些信息来检查邮件是否发送成功。它总是打印“发送电子邮件”消息并打开内置电子邮件客户端并发送电子邮件。

【问题讨论】:

  • 我也有同样的问题。出于某种原因,我的 onActivityResult 没有触发;您是如何得知电子邮件已发送的?

标签: android email android-intent


【解决方案1】:

您不能使用 android.content.Intent.ACTION_SEND 来执行此操作。 只需尝试使用邮件应用程序将邮件发送到不存在的电子邮件 ID。您将看到该应用程序不会通知您交付失败。使用 android.content.Intent.ACTION_SEND,您实际上是在向同一个应用程序传递一个意图来为您完成电子邮件传递任务。因此,您永远不会知道您的邮件投递是否失败。

解决方法。 您需要使用 3rd 方库 mail.jar 或类似的东西来实现电子邮件传递。但问题是您需要同时拥有发件人的 mailID 和 PASSWORD 才能进行设置。也许您可以拥有一个可以发送邮件的虚拟电子邮件帐户。

This 可以帮忙。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 2016-01-23
    • 1970-01-01
    • 2013-11-06
    • 2016-09-22
    相关资源
    最近更新 更多