1

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

Jasser
  • 65
  • 1
  • 9

1 Answers1

2

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.

ElectronicGeek
  • 3,312
  • 2
  • 23
  • 35
  • What i want to do is let users send email containing information from within my app, that is why i need to specify the sender's email because it will always be mine – Jasser Mar 12 '14 at 14:58
  • You can't allow the users to send an email for you, they will have to send an email with their own address. – ElectronicGeek Mar 12 '14 at 14:59
  • I am trying to let the user send a copy of his/her online order details for themselves. it isn't possible ? – Jasser Mar 12 '14 at 15:02
  • You can't specify the sender, but you can specify the body. You could just specify the body with the info, and let the user pick which email to send from. If you want to send the email from your email, you will have to do it from an external server, I believe. – ElectronicGeek Mar 12 '14 at 15:06
  • I found something called " SMTP", is it possible to use it to specify permanent sender's email and password ? – Jasser Mar 12 '14 at 15:10
  • Maybe, but you'd have to find an open sourced library that allowed you to use this. Plus, I don't think it would be supported by the email apps installed, so you'd have to make your own editor. Here's an example of it in use, it may work: http://stackoverflow.com/questions/4345032/how-to-send-a-simple-email-programatically-exists-a-simple-way-to-do-it – ElectronicGeek Mar 12 '14 at 15:14