4

I want to be able to send an email out of my app, based on the user pressing a button on my app's Activity. The email needs to be sent automatically by the application upon button press, i.e. I don't want to show another email form to the user. And the email should be sent using the user's default email account on the phone not an email account that I hardcode into my app. And I don't want to have the user key in their email credentials into my app's configuration, I just want to be able to call some android api and say "send this email with this subject and body to this email address, using the default account that the user has set up on the phone".

Is this possible? If so, how?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Prabhu M
  • 3,534
  • 8
  • 48
  • 87
  • possible duplicate of [How to send email from android (using the default account) ?](http://stackoverflow.com/questions/4541111/how-to-send-email-from-android-using-the-default-account) – Aleadam May 17 '11 at 13:58
  • I dont want switch to any activity to send email. I want to send it in background – Prabhu M May 17 '11 at 14:05
  • Did you get solution for your question? If yes, can you post your code please. I tried sending mail with hardcoded username and password.But i dont want that.I want to get username and password from user. – swathi Jun 05 '12 at 05:53
  • Hi, Did any one here in this post found any solution. I'm stuck on the same issue. I'm able to send email in the background by hard-coding id/password, but I wanna use devices default account to send the email. – SaK Mar 20 '14 at 12:10

1 Answers1

6

To send in the background, see the first link at your right on the list of related questions:

You need to use an email API such as JavaMail:

Sending Email in Android using JavaMail API without using the default/built-in app

Update based on the comments:

There is no way to send an email silently, without either:

  • letting the user know and accept it first (by using intents and an email provider)
  • or asking for the username and password before and using an email API as above (the user will implicitly give you the approval to send/receive emails by entering those values)

And that is a very good thing! There are too many security concerns otherwise. If you ever find a way, please post it as a bug report in android.

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • 1
    Hi, it needs to set userid and password of sender . I want to send email using default user account of android phone – Prabhu M May 17 '11 at 14:17
  • So you want to send an email silently, without letting the user know, and using the users passwords without asking for them? Well, I think that's borderline criminal. – Aleadam May 17 '11 at 15:20
  • I am developing a security application. so I dont want to let the thief knowing email is sending.. so I want send email in background.. – Prabhu M May 18 '11 at 06:24
  • @prabhu then ask for the user/pass combo once upon first run, store them, and use them later with the javamail api. You would expect that no thief will install the app, so what's the problem with that approach? – Aleadam May 18 '11 at 06:41
  • @Aleadam if user already registered with his account, why we cannot send an email from his account without Intent.ACTION_SEND. if we use Intent.ACTION_SEND, only probem is, it is not giving any result code in onActivityResult() method. If we use JAVA Mail API, then user again enter username and password. Is there any alternative solution? thanx in advance.... – sandeepmaaram Mar 13 '14 at 14:44