简体   繁体   English

Android-发送电子邮件而无需用户按SEND

[英]Android - Send email without user press SEND

I have an app that needs to send email without user interaction. 我有一个需要在没有用户交互的情况下发送电子邮件的应用程序。 I've developed this code that set the default email client as GMAIL, but is necessary press SEND. 我已经开发了将默认电子邮件客户端设置为GMAIL的代码,但是必须按SEND键。

Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
    emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    emailIntent.setType("plain/text");
    emailIntent.setClassName("com.google.android.gm", "com.google.android.gm.ComposeActivityGmail");
    emailIntent.setData(Uri.parse("mailto:"));
    emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"user@mail.com"});
    emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "SUBJECT TEXT");
    emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "body text");
    startActivity(emailIntent);

After that, it will show the email form with fields filled and the user needs to press SEND button. 之后,它将显示带有填写字段的电子邮件表单,用户需要按SEND按钮。 Does someone know how to send automatically ? 有人知道如何自动发送吗?

Gmail client waiting for user action to press SEND button Gmail客户端正在等待用户按“发送”按钮

You can do this by java mail api. 您可以通过Java Mail API执行此操作。

For that you have to add some jar files. 为此,您必须添加一些jar文件。

You have to follow this link because it worked for me. 您必须点击此链接,因为它对我有用。

http://www.javatpoint.com/example-of-sending-email-using-java-mail-api http://www.javatpoint.com/example-of-sending-email-using-java-mail-api

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

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