gpt4 book ai didi

java - 如何从我的应用程序向 android studio 中的用户发送电子邮件?

转载 作者:行者123 更新时间:2023-12-01 16:14:42 25 4
gpt4 key购买 nike

我希望我的移动应用程序向登录该应用程序的用户发送一封电子邮件,其中包含有关其健康状况的一些附加信息。我已经搜索过,但只找到了如何撰写电子邮件并将其发送给某人,我没有找到一些教程来展示如何使您的应用程序向用户发送电子邮件。您知道这是否可以实现吗?如果您有任何提示,或者您知道一些好的教程,请与我分享信息。

最佳答案

不太确定是否可能,抱歉。但是,您可以撰写邮件,并以编程方式向其中添加数据,以便在自己按“发送”之前阅读全部内容

假设:

  1. 您将记录的用户邮件存储在字符串等变量中。
  2. 我们添加数据并撰写邮件,因此设备必须至少有一个邮件应用程序。我已使用 GMAIL 应用对此进行了测试。

代码:

//Define your mail:
String USERmail = "user@home.com";
String HealthData = "70kg";
String file1 = "/Dir1/Xray.jpg" //Data you might need to attach to mail
String file2 = "/Dir1/Fat.jpg" //Data you might need to attach to mail

//=======================Add files to variable - bucle might be needed==========
String[] attached = new String[2]; // 2 number of files
attached[0] = file1;
attached[1] = file1;

//=========================Compose Mail========================================
Intent sendintent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sendintent.putExtra(Intent.EXTRA_EMAIL, new String[]{USERmail});
sendintent.putExtra(Intent.EXTRA_SUBJECT, "String cointaining subject");
sendintent.putExtra(Intent.EXTRA_TEXT, "Greetings Text" +yourdata); //Add your health data

//==============Attach Method in case any data needed to be sent==============
ArrayList<Uri> uris = new ArrayList<Uri>();
for(String filepath : attached)
{File fileATCH = new File(filepath);
Uri u = Uri.fromFile(fileIn);
uris.add(u);
}
sendintent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
sendintent.setType("text/plain");

//================================================ ===================================startActivity(Intent.createChooser(sendintent, "发送健康邮件..."));//选择 GMAIL 或您可能拥有的任何其他邮件应用程序。我只用 GMAIL 测试过。

希望这会有所帮助!

关于java - 如何从我的应用程序向 android studio 中的用户发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62437474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com