Send Email Using An Intent In Xamarin Android App, Using Visual Studio 2015


Xamarin is a platform to develop cross-platform and multi-platform apps (Ex. Windows phone, Android, iOS). The code-sharing concept is used in Xamarin. The Xamarin Studio is available in the Visual Studio also.

How to compose and send email using Intent


  • Visual Studio 2015 update 3

The following steps are needed to be followed in order to send the Email using Intent in Xamarin Android app.

Step 1

Click File-->  New--> Project, or click (Ctrl+Shift+N). This will open the list of all types of projects available in Visual Studio.


Step 2

Select Installed --> Templates --> Visual C# --> Android --> choose the Blank App (Android).

Next, give your Android app a name (Ex:sample) and assign the path of your project. Click OK.


Step 3

Next, go to the Solution Explorer and select Resource -->Layout. Double click to open main.axml page. Select either the Source tab or Designer tab depending on your expertise of designing the application.


Step 4

The main.axml file will open in the main page designer.


Delete the Linear Layout and default "hello world" button by removing the coding from source panel.

Now, delete the C# button action code from MainActivity.cs page.

Step 5

Next, go to the toolbox window and scroll down until you see all the tools and controls.

Drag and drop a Button to your application.


Step 6

Next, go to the properties window and edit the Button id value and Text value.

(Ex:android:id="@+id/myButton" android:text="@string/buttonText").


Step 7

In this step, go to the Main.axml page Source Panel. Note the Button id value.


  1. <LinearLayout xmlns:android="" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent">  
  2.     <Button android:id="@+id/myButton" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/buttonText" />  
  3. </LinearLayout>  
Step 8

In this step, open the String.xml page. Go to the Solution Explorer--> Resource--> values--> String.xml.


Step 9

After opening the String.xml file, write the following xml code.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <resources>  
  3.     <string name="buttonText">Send an email</string>  
  4.     <string name="app_name">SendEmail</string>  
  5. </resources>  

Step 10

Next, go to the MainActivity.cs page. Write the following code in the OnCreate() Method.

  1. protected override void OnCreate(Bundle bundle) {  
  2.     base.OnCreate(bundle);  
  3.     // Set our view from the "main" layout resource  
  4.     SetContentView(Resource.Layout.Main);  
  5.     Button button = FindViewById < Button > (Resource.Id.myButton);  
  6.     button.Click += delegate {  
  7.         var email = new Intent(Android.Content.Intent.ActionSend);  
  8.         email.PutExtra(Android.Content.Intent.ExtraEmail, new string[] {  
  9.             "",  
  10.             ""  
  11.         });  
  12.         email.PutExtra(Android.Content.Intent.ExtraCc, new string[] {  
  13.             ""  
  14.         });  
  15.         email.PutExtra(Android.Content.Intent.ExtraSubject, "Hello Xamarin");  
  16.         email.PutExtra(Android.Content.Intent.ExtraText, "Hello Xamarin This is My Test Mail...!");  
  17.         email.SetType("message/rfc822");  
  18.         StartActivity(email);  
  19.     };  
  20. }  

Step 11

If you have Android Virtual device, run the app on it. Else, connect your Android phone and run the app in that.

Simply, connect your phone and go to Visual Studio. The connected phone will show up in the Run menu (Ex:LENOVO A6020a40(Android 5.1-API 22)). Click the Run option.



After a few seconds, the app will start running on your phone.

You can tap the "Send an Email" button now.


Choose "Share with Gmail" and tap "Just once".


It will show To, cc, Subject and body of the message. Fill the details and tap"Send".




So, this was the process of sending an Email using an Intent in Xamarin Android app, using Visual Studio 2015.