从Android应用程序发送电子邮件,指定发件人的电子邮件

时间:2014-03-12 14:38:43

标签: android email

我正在尝试从我的Android应用发送电子邮件。 这段代码对我来说效果很好

public void sendEmail(View v)
{
    StringBuilder msgBody = new StringBuilder();
    msgBody.append("name ").append("me").append("\n");
    msgBody.append("name ").append("you").append("\n");

    Intent intent = new Intent(Intent.ACTION_SENDTO); // it's not ACTION_SEND
    intent.setType("text/plain");
    intent.putExtra(Intent.EXTRA_SUBJECT, "Subject of email");
    intent.putExtra(Intent.EXTRA_TEXT, " "+ msgBody.toString());
    intent.setData(Uri.parse("mailto:user@hotmail.com")); // or just "mailto:" for blank
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // this will make such that when user returns to your app, your app is displayed, instead of the email app.
    startActivity(intent);
}

使用此代码,我可以指定接收的电子邮件。 但是,我还需要指定发件人电子邮件。

有任何帮助吗?提前谢谢

1 个答案:

答案 0 :(得分:2)

您无法指定发件人的电子邮件,因为用户可能没有该电子邮件。您只能指定用户应将其发送给谁,建议的消息和主题。

例如,如果我的电子邮件是example1@gmail.com,但您希望我以example@gmail.com发送电子邮件,则会出现错误。

相关问题