2

Not a duplicate

I want to sent email without using any default email app so I searched a little bit and I stumbled upon this solution using JavaMail API -

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

But I have few issues with this solution -

I don't want to use static username and password. Instead of that I want to use user's email ID. But it'll not be a good design if I directly ask user to enter his or her password.

So, how can I achieve this in a better way. Sorry, if this sounds too broad. Just looking for ideas not actual code.

Community
  • 1
  • 1
Mandeep Rajpal
  • 1,667
  • 2
  • 11
  • 16
  • 1
    There is no such thing as a "user's primary email id". A phone *might* have a gmail account attached to it, but that doesn't mean he actually uses gmail (I have a gmail account on my phone, but I've never used it to send email in my life, nor do I wish to). – Gabe Sechan Feb 10 '16 at 22:55
  • @GabeSechan My bad, I actually meant gmail account attached to play store. I am looking for anything except for using hard coded ID and password. – Mandeep Rajpal Feb 10 '16 at 23:07

2 Answers2

2

Please, take a look at the Gmail API Android Quickstart guide. You'll be able to get the account credentials from Google Play Services and authenticate your user with OAuth2 by prompting an account selection

archived
  • 647
  • 8
  • 24
1

Instead of that I want to use user's email ID

As Gabe indicated, there is no "user's email ID" in Android. Beyond that, an "email ID" is insufficient for sending an email. You would have to ask the user both for all their email account information (username, password, SMTP server, etc.). Unless you are writing a full email client, hopefully nobody will give you this information.

how can I achieve this in a better way

Use ACTION_SEND or ACTION_SENDTO.

Or, send the email from your Web server, where your app tells the Web server what message to send via a Web service API that you implement and adequately secure. Then, you can use your own email account credentials without having to bake them into the app.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491