0

I have a requirement to open the email client with text file attachment. I followed the answer in SO link, however it opens all other sharing apps and let user to choose Email client before. I need to open default email client with attachment

Opening an email client on clicking a button

Tried out 1: I tried to change

intent.setType("plain/text");

to

intent.setType("message/rfc822");

Tried out 2 : I included the following line

 string fileLocation;
 Intent intent = new Intent(Intent.ActionView);
 intent.SetType("message/rfc822");
 intent.SetData(Android.Net.Uri.Parse("mailto:" + "support@yyy.com"));
 intent.PutExtra(Intent.ExtraSubject, "Help");
 string messageBody = "sdfasfasdf";
 intent.PutExtra(Intent.ExtraText, Android.Text.Html.FromHtml(messageBody));
 Java.IO.File emailAttachment = new Java.IO.File(fileLocation);
 intent.PutExtra(Intent.ExtraStream, Android.Net.Uri.FromFile(emailAttachment));
 Intent mailer = Intent.CreateChooser(intent, "");
 context.StartActivity(mailer);

This solution opens the email client alone perfectly. However, the attachment was not included.

Any other ideas!!

Community
  • 1
  • 1
Anees Deen
  • 1,385
  • 2
  • 17
  • 31

0 Answers0