I am trying to send an email from my android app. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.