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.1K+ Learners
    4.42  (351)
    Generics in Java
    1 hrs
    Beginner
    1.1K+ Learners
    Introduction to Spring Framework
    1 hrs
    Beginner
    2.6K+ Learners
    4.33  (160)
    Introduction to Appian
    2 hrs
    Beginner
    937 Learners
    4.32  (38)
    Introduction to Blue Prism
    1 hrs
    Beginner
    467 Learners
    4.63  (38)
    Fundamentals of UiPath
    1 hrs
    Beginner
    1K+ Learners
    4.56  (78)
    ASP.NET MVC Course for Beginners
    1 hrs
    Beginner
    4.4K+ Learners
    4.47  (205)
    Java Virtual Machine Introduction
    2 hrs
    Beginner
    987 Learners
    4.49  (57)