我正在尝试从我的 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,就会报错。
关于android - 从指定发件人电子邮件的 Android 应用程序发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22354886/