简体   繁体   English

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

[英]Sending email from android app specifying sender's email

I am trying to send an email from my android app. 我正在尝试从我的android应用发送电子邮件。 It works well for me with this code 此代码对我来说很好

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);
}

With this code i can specify the reception's email. 使用此代码,我可以指定接待人的电子邮件。 However, i need to specify the senders email as well. 但是,我还需要指定发件人电子邮件。

Any help ? 有什么帮助吗? thanks in advance 提前致谢

You can't specify the sender's email, because the user may not have that email. 您无法指定发件人的电子邮件,因为用户可能没有该电子邮件。 You can only specify who the user should send it to, the suggested message, and subject. 您只能指定用户应将其发送给谁,建议的消息和主题。

For example, if my email is example1@gmail.com, but you want me to send the email as example@gmail.com, then there will be an error. 例如,如果我的电子邮件为example1@gmail.com,但是您希望我将电子邮件作为example@gmail.com发送,则将出现错误。

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

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