Skip to main content

Android How to Send Email programmatically

In this tutorial, you will see how to send an email from your own android application. To do that, Android provides the Intent.ACTION_SEND , which means that your Activity want to send some data(in our case:email, cc, bcc, subject, attachements …) to another Activity(it may be an Activity in your own application, or in another application). The activity which will receive this sent data is not specified, it is up to the receiver of this action to ask the user where the data should be sent. That’s why you should give the user the choice of how to send data by wrapping it into Chooser (through createChooser(Intent,CharSequence) ).
  • Send Email :

  • Send Email with attachement:

NOTE : Android does not provide an API to send Email directly.If the device has no email client application configured, then you will got the error “No application can perform this action”. This is the case when you try to run this application on Emulator. That’s why you should test it on a real device with at least one email clients application installed and configured.
  • Demonstration :

You can download the source of the demo application from here
And here is some Screen shots :
This is the default screen of the demo:
layout send email application android
Fill in details : email, subject and a message body. Click the send button:
layout_demo_send_mail_android
After the button click, the app will prompt all installed email clients application on your device. Select one of them to send the email ( in my case i have picked Gmail)
chooser ACTION_SEND
Finally, all previous filled in informations will be populated to Gmail application automatically.
gmail_composer

Comments

Popular posts from this blog

Android Alarm Manager Example

AlarmManager Many a times we want some task to be performed at some later time in future. For Example: In SMS Scheduler we want a SMS to be send at some later time, or Task Reminder in which we want to be reminded  about a task at a particular time, to implement all these things we use AlramManager class. AlarmManager class provides access to the system alarm services. These allow you to schedule your application to be run at some point in the future. When an alarm goes off, the  Intent  that had been registered for it is broadcast by the system, automatically starting the target application if it is not already running. Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.                   The Alarm Manager holds a CPU wake lock as long as the ...

MVVM Android Example

  What is MVVM? For a start, let's consider the classical description of this template and analyze each of its components.  Model-View-ViewModel  (ie  MVVM ) is a template of a client application architecture, proposed by John Gossman as an alternative to MVC and MVP patterns when using Data Binding technology. Its concept is to separate  data presentation logic  from  business logic  by moving it into particular class for a clear distinction. So, what does each of the three parts in the title mean? Model is the logic associated with the application data. In other words, it is POJO, API processing classes, a database, and so on. View is actually a layout of the screen, which houses all the widgets for displaying information. ViewModel is an object which describes the behavior of View logic depending on the result of Model work. You can call it  a behavior model of View . It can be a rich text formatting as well as a component visibility contr...