繁体   English   中英

从android应用发送电子邮件,指定发件人的电子邮件

[英]Sending email from android app specifying sender's 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);
}

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

有什么帮助吗? 提前致谢

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

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

暂无
暂无

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

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