email sent without putting the password into the c

2019-07-20 19:44发布

问题:

Is there anyway to get an email sent without putting the password into the code ?

There are many email api-s that enables to send an email with entering the username and password.

Example

sendEmail("myemail@gmail.com","mypass","subject","msg body"); 

Is there any way around the problem with hard-coding the password in code ?

回答1:

You have three options to send email:

  1. You include your email and password into the code and in this case the application will send emails from this email address.
  2. You can ask user to enter his credentials for his email and in this case you'll receive a mail from user's address.
  3. You can form an intent in your application that will fill neccessary fields and call user's email client to send this.

If you want silent way to send email then you should choose 1 or 2. But more secure way is to use the third approach.



回答2:

You can ask the user password one time and then store it in your internal storage. It may be necessary to add a way to change the password later if preferred. Deciding from documentation, the internal storage is even secure, while it is also possible to use additional encryption. This is how most of E-mail clients work.