How to code using android studio to send email

I plan to develop an Android mobile application using the Android studio, where the user gives an email address and a secret code. Then this secret code should be sent to the specified email address. Can any authority use any piece of code for this?

+8
android
source share
1 answer

If you want to send an email in the background, contact here

If the user is waiting on the screen, use the method below:

protected void sendEmail() { Log.i("Send email", ""); String[] TO = {"someone@gmail.com"}; String[] CC = {"xyz@gmail.com"}; Intent emailIntent = new Intent(Intent.ACTION_SEND); emailIntent.setData(Uri.parse("mailto:")); emailIntent.setType("text/plain"); emailIntent.putExtra(Intent.EXTRA_EMAIL, TO); emailIntent.putExtra(Intent.EXTRA_CC, CC); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject"); emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here"); try { startActivity(Intent.createChooser(emailIntent, "Send mail...")); finish(); Log.i("Finished sending email...", ""); } catch (android.content.ActivityNotFoundException ex) { Toast.makeText(MainActivity.this, "There is no email client installed.", Toast.LENGTH_SHORT).show(); } } 
+14
source share

All Articles