Send Email From an Android Application programmatically

android-logo

Here we will discuss about how to send Email from an Android application programmatically. Simple we will use Intent.ACTION_SEND action with an existing email client like (gmail or something else) to send the email. Here in our example we will take inputs from user ( like To, Subject, Message) and will send it by invoking any of the existing email client, which is already installed in your device.

Below is the reference as per the example explained here. Once you download the source code from here then you will  find the inline comments inside the source code for complete understanding. This application is developed in Eclipse Indigo version.

1. Create a Android Project named as: SendEmailInAndroid

2. Enter the package name  as: package com.techblogon.sendemailinandroid

3. Create the project with default setting.

3. Your xml file looks like below, which contains simple controls like To, Subject, Message field etc.

File name: activity_main.xml in ../res/layout/activity_main.xml in your project directory.

Note: In the above xml file, we have a button and it’s attribute called onClick with the function name onButtonClickSend . This will be use in our main activity java class directly.

4. File name: Activity Class ( MainActivity.java)

When user will fill all details and click on the send button from the screen, then onButtonClickSend(View v) function will be called from the activity class as below code.

5. Build and run this application on your device.

Demo

1. Fill all details like below screen and click on Send button.

send-email-in-android-example

2. After click on Send button as above, a new screen will appear which you need to choose an existing email client. In my case i have selected GMail client from the list.

send-email-in-android-example-choose-email-client

3. After choose a existing client from the list as above, all your data will be automatically filled in the email client and then click on send option in Gmail to send your email.

Note: If no default client is present in your device then you need to add an email client first then this application will work.

downloadDownload Send Email From an Android Application example source code from here.

I hope this small tutorial will help you at it’s best.

 

Post By SmrutiRanjan (57 Posts)

Working @ Samsung as a Project Lead for Android Smartphones. I have been blogging since 2008. Previously I was writing articles for other bloggers, but finally I have started my own blog-"Techblogon".I am also an active contributor for the blog-"Gadgets n Gizmos World". Job is my necessity, but blogging is my passion.

Website: → Techblogon

Connect

Leave a Reply

Your email address will not be published. Required fields are marked *


× 7 = fifty six

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">