0

I did not find any useful information.

Is there a best way to send mails from my android application? is it secure to store the user and password in the code? (I guess not) And whats the best way, if I want to send mails from the mail, the user is using on his phone? (via code)

  • you can use Intents to send emails – Chaitanya K Nov 09 '16 at 06:18
  • @ChaitanyaKurdukar yeah, but that means, the user must interact with it. It shoud be send automatically, but I could not find a way to do this with Intents. – SettusBlake Nov 09 '16 at 06:19
  • ok but if you want to use the application that user is using this is the way it works on android as per my knowledge. What is your use case? Why you want to send mail without user's knowledge? – Chaitanya K Nov 09 '16 at 06:20
  • its for a secret santa app. The user hits a button, and every user in the list should get an email. For secret santa, the user who uses the app should not see the content of the mail. – SettusBlake Nov 09 '16 at 06:40
  • Ok then using the java mail API will be suitable in this case – Chaitanya K Nov 09 '16 at 06:47
  • Yeah, but the main problem here is, the user and the password I think. It should not stored in the code, but I could not find a good solution for that. – SettusBlake Nov 09 '16 at 06:49
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/127687/discussion-between-chaitanya-kurdukar-and-settusblake). – Chaitanya K Nov 09 '16 at 06:50

2 Answers2

0

For storing userId and password you can use sharedpreferences. To send mail via android Email application you can use below code.

Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
            "mailto","abc@gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Body");
startActivity(Intent.createChooser(emailIntent, "Send email..."));

Hope this helps.

Update: It seems that on 4.3, we need to pass string array instead of a string for email address to make it work. We might need to add one more line:

intent.putExtra(Intent.EXTRA_EMAIL, addresses); // String[] addresses
Chaitanya K
  • 1,827
  • 4
  • 32
  • 67
0

You shouldn't store any pasword, just only access token that provided by the server, or store and compare has code of password

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
Alex Shutov
  • 3,217
  • 2
  • 13
  • 11