Introduction
Hello all! In this article, we will learn how to create an Android app that will send an email using any email client. In this tutorial, we are using the intent service of Android which will help us to send the email. The intent is very useful in Android development. It helps us to call the needed services, like calling, SMS, GPS, etc. It has a wider role in Android.
Requirements
- Android Studio 2.3.3
- Little knowledge of Java and XML
- Android Phone to test the Android app
Let’s get started.
Let’s start creating the Android app using Android Studio. I have also given the download link of the project, that you can find below.
Step 1 - Creating a new project with Android studio
Open Android Studio and create a new project, name it as "Send Email" and give a company domain whatever you like; for eg: foo.android (You can use your own name also).
- Click "Next" and choose Min SDK; I have chosen Android 4.1 (Jelly Bean).
- Click "Next" and select "Empty Activity".
- Choose the Activity as Main Activity and click "Next", then "Finish".


Once we create our new project, Gradle will take some time to sync the project and will resolve all the dependencies. Sometimes, this process also takes a lot of time.
Step 2 - Creating Layout of Send Email App
Here, we will create a layout for our app. So, for tutorial purposes, I am keeping it simple. For sending an email, we usually need three fields, i.e., To, Subject, and Message. So, we will be creating a layout for three fields with the help of TextView and EditText and finally, we need a Send button to send the email.
The XML code for our layout is shown below.
activity_main.xml
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- tools:context="in.amitsin6h.sendemail.MainActivity"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingLeft="20px"
- android:paddingRight="20px"
- android:orientation="horizontal"
- >
- <EditText
- android:id="@+id/etTo"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_alignParentTop="true"
- android:layout_marginRight="22dp"
- android:layout_marginTop="16dp"
- android:ems="10" />
- <EditText
- android:id="@+id/etSub"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/etTo"
- android:layout_below="@+id/etTo"
- android:layout_marginTop="18dp"
- android:ems="10" >
- </EditText>
- <EditText
- android:id="@+id/etMsg"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/etSub"
- android:layout_below="@+id/etSub"
- android:layout_marginTop="28dp"
- android:ems="10"
- android:inputType="textMultiLine" />
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/etTo"
- android:layout_alignBottom="@+id/etTo"
- android:layout_alignParentLeft="true"
- android:text="To:" />
- <TextView
- android:id="@+id/textView2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/etSub"
- android:layout_alignBottom="@+id/etSub"
- android:layout_alignParentLeft="true"
- android:text="Subject:" />
- <TextView
- android:id="@+id/textView3"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignBaseline="@+id/etMsg"
- android:layout_alignBottom="@+id/etMsg"
- android:layout_alignParentLeft="true"
- android:text="Message:" />
- <Button
- android:id="@+id/btSend"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignLeft="@+id/etMsg"
- android:layout_below="@+id/etMsg"
- android:layout_marginLeft="76dp"
- android:layout_marginTop="20dp"
- android:text="Send" />
- </RelativeLayout>





shweta ChaudharyPosted Feb 14, 2018, 5:46 AM
Hey...thanks for the information.....
Lokesh SharmaPosted Feb 7, 2018, 5:31 AM
Thank you, it is really helpful.
Sagar Pandurang KapPosted Feb 6, 2018, 10:26 PM
Great work yaarr...