Android

Android - Sending Email

Android - Sending Email

Sending Emails can also be implemented using Android. Email is just like a message that can be sent from one user to another user via a network. In Android, you can send an email from your application without implementing it, just by using the default Email app provided by android like Email, Gmail, Outlook etc. 
There are different Intent objects required to send an email that is described below:

Action required to send Email: To launch an email client on your android device, you will have to use ACTION_SEND action. The syntax given below is used to create an intent:

Intent mailAction = new Intent(Intent.ACTION_SEND);

Type to send mail: As we are familiar with sending mail where you need to specify where you need to send the mail, i.e. ‘mailto:’. Here we provide the URI of the recipient with the help of the setData() method. You can also follow the code snippet shown below for your reference where we also defined the setType() method:

emailIntent.setData(Uri.parse(“mailto:”));
emailIntent.setType(“text/plain”);

Attachments in the mail or other extras: Android comes with default support where you can use TO, SUBJECT, CC, BCC etc. fields in your mail without sending it to the main recipient. Refer to the example below for a better understanding:

emailIntent.putExtra(Intent.EXTRA_EMAIL  , new String[]{"Recipient_Add"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject_Here");
emailIntent.putExtra(Intent.EXTRA_TEXT   , "This is the main body of the mail.");


 

Top course recommendations for you

    Introduction to Application Security
    1 hrs
    Beginner
    4.5K+ Learners
    4.43  (423)
    Generics in Java
    1 hrs
    Beginner
    1.2K+ Learners
    Introduction to Spring Framework
    1 hrs
    Beginner
    2.9K+ Learners
    4.49  (290)
    Introduction to Appian
    2 hrs
    Beginner
    973 Learners
    4.38  (48)
    Introduction to Blue Prism
    1 hrs
    Beginner
    499 Learners
    4.65  (51)
    Fundamentals of UiPath
    1 hrs
    Beginner
    1.1K+ Learners
    4.63  (108)
    ASP.NET MVC Course for Beginners
    1 hrs
    Beginner
    4.5K+ Learners
    4.47  (222)
    Java Virtual Machine Introduction
    2 hrs
    Beginner
    1K+ Learners
    4.5  (64)