Android:如何确认电子邮件已成功发送 [英] Android: How to confirm that email has been sent successfully
问题描述
这是我能够成功发送电子邮件的代码
Here is my code that is able to sent email successfully
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();
}
}
}
}
我想获取一些信息以检查电子邮件是否已成功发送。它总是打印消息发送电子邮件,并打开内置的电子邮件客户端并发送电子邮件。
I want to get some information back to check whether the email has been sent successfully or not. It always prints the message "send email" and opens built-in email client and sends email.
推荐答案
您不能使用:android.content.Intent.ACTION_SEND。
只是尝试使用邮件应用程序发送邮件到不存在的电子邮件ID。您会看到应用程序没有通知您交货失败。使用android.content.Intent.ACTION_SEND,您实际上将意图传递给同一个应用程序,为您执行电子邮件传送任务。所以你永远不会知道你的邮件传递是否失败。
You cannot do this using : android.content.Intent.ACTION_SEND. Just try to send a mail using the mailing app to a email ID that doesnot exist. You will see that the app does not notify you of the failed delivery. Using android.content.Intent.ACTION_SEND, you are actually passing an intent to the same app to do the email delivery task for you. So you will never know if your mail delivery has failed.
您需要实现电子邮件传递第三方库的mail.jar或类似的东西。但事情是你需要发送者的mailID和PASSWORD来设置它。可能你可以有一个可以发送邮件的虚拟电子邮件帐户。
The work around. You need to implement the email delivery a 3rd party Library mail.jar or some thing similar. But the thing is you need to have senders' mailID and PASSWORD both to set this up. May be you can have a dummy email account with which you can send the mail.
This 可以帮助。
这篇关于Android:如何确认电子邮件已成功发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!