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
    2.2K+ Learners
    4.54  (114)
    Generics in Java
    1 hrs
    Beginner
    686 Learners
    Introduction to Spring Framework
    1 hrs
    Beginner
    1.7K+ Learners
    Introduction to Software Development Security
    2 hrs
    Beginner
    3K+ Learners
    Introduction to Appian
    2 hrs
    Beginner
    753 Learners
    4.41  (27)
    Introduction to Blue Prism
    1 hrs
    Beginner
    344 Learners
    4.6  (20)
    Introduction to Apache Pig
    2 hrs
    Beginner
    215 Learners
    Fundamentals of UiPath
    1 hrs
    Beginner
    663 Learners
    4.49  (37)
    ASP.NET MVC Course for Beginners
    1 hrs
    Beginner
    3.5K+ Learners
    4.6  (125)
    Java Virtual Machine Introduction
    2 hrs
    Beginner
    708 Learners
    4.68  (25)