G.Mich
G.Mich

Reputation: 1666

Send email with subject and body Xamarin Forms

I am using the following code in my Xamarin.Forms project to open the native email client on the device with some information prepopulated in the body, but the email client on Android opens without a set body and subject; it only has the mailto property.

The following code works for iOS, but on Android, it opens the email clientand only displays mailto.

string body = "Name : "+"\r\n" +NameLabel.Text +"Phone : "+Phonelabel.Text +"\r\n"+ "Email : "+ EmailLabel.Text ;

string strMailTo = @"mailto:[email protected]?Subject="profile"&Body="+body;

Device.OpenUri(new Uri(strMailTo));

Upvotes: 2

Views: 6685

Answers (3)

FetFrumos
FetFrumos

Reputation: 5944

I used in Xamarin.Forms DependencyService and this code:

var email = new Intent (Android.Content.Intent.ActionSend);
email.PutExtra (Android.Content.Intent.ExtraEmail,
new string[]{"[email protected]", "[email protected]"} );
email.PutExtra (Android.Content.Intent.ExtraCc,
new string[]{"[email protected]"} );
email.PutExtra (Android.Content.Intent.ExtraSubject, "Hello Email");
email.PutExtra (Android.Content.Intent.ExtraText,
"Hello from Xamarin.Android");

it full example

Upvotes: 1

noelicus
noelicus

Reputation: 15055

I have code that uses Device.OpenUri from Xamarin Forms. I think perhaps your quotes are confusing it:

Device.OpenUri(new Uri("mailto:[email protected]?subject=MobileTing&body=A message for you consideration."));

Upvotes: 3

Alessandro Caliaro
Alessandro Caliaro

Reputation: 5768

I think you can try this plugin. I have used for some apps and works fine. It's PCL.

https://www.nuget.org/packages/Xam.Plugins.Messaging/

Upvotes: 5

Related Questions