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

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

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

有什么帮助吗?提前致谢

最佳答案

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

比如我的邮箱是example1@gmail.com,但是你要我发邮件到example@gmail.com,就会报错。

关于android - 从指定发件人电子邮件的 Android 应用程序发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22354886/

相关文章:

android - Android广播是否按顺序接收?

php - 如何邮寄使用 php 创建的图像

php - 确认电子邮件未从 php 和 mysql 数据发送?

Java 邮件可运行 jar 未运行

android - 为 Android 中的交易电子邮件集成 Mailchimp 的 Mandrill

android - Arduino LED 闪烁问题

android - 使用红外线检测 ios 或 android 设备中的对象

Android - 为什么背景图片让按钮看起来很奇怪?

android - com.facebook.widget.ProfilePictureView - 错误 : Error parsing XML: unbound prefix

PHP mail() 电子邮件地址与发送的电子邮件不同