I'm trying to send a mail along with multiple files attached to it, however I can't get them to be added to the mail. I proceed like this:
private void SendMail (List<Data> ToSend)
{
var Attachments = new List<Android.Net.Uri>();
Intent i = new Intent (Android.Content.Intent.ActionSendMultiple);
i.SetType ("message/rfc822");
i.PutExtra (Android.Content.Intent.ExtraEmail, new String[]{"try@mail.com"});
i.PutExtra (Android.Content.Intent.ExtraSubject, "Test");
i.PutExtra (Android.Content.Intent.ExtraText, "Test Test...");
foreach (var content in ToSend) {
Java.IO.File myFile = new Java.IO.File(content.attachmentloc);
// attachmentloc is a string containing the absolute path to the file to attach.
var uri = Android.Net.Uri.FromFile(myFile);
Attachments.Add (uri);
}
i.PutParcelableArrayListExtra(Android.Content.Intent.ExtraStream, Attachments.ToArray());
StartActivityForResult(Intent.CreateChooser(i, "Send mail..."), 0);
}
I checked and the path in the string is good.. however the method .Exists (When used on the Java.IO.File in the foreach) returns false. might be the reason why ?
Thanks for the help.
EDIT:
When trying to add a single attachment, it works just fine. However whenever I call a function that imply there will be more than one attachment, it fails.
Aka:
Intent i = new Intent (Android.Content.Intent.ActionSend);
var uri = Android.Net.Uri.Parse (ex._FileLocation);
i.PutExtra(Intent.ExtraStream, uri);
Works just fine however replacing
Intent i = new Intent (Android.Content.Intent.ActionSend);
By
Intent i = new Intent (Android.Content.Intent.ActionSendMultiple);
Leads to the same fail and so does replacing:
var uri = Android.Net.Uri.Parse (ex._FileLocation);
i.PutExtra(Intent.ExtraStream, uri);
By
var Attachments = new List<Android.Net.Uri> ();
foreach (var ex in ToSend) {
var uri = Android.Net.Uri.Parse (ex._FileLocation);
Attachments.Add (uri);
//o
}
i.PutParcelableArrayListExtra (Android.Content.Intent.ExtraStream, Attachments.ToArray ());
... I'm using the default mail application (not gmail) I also tried setting the intent type to " * / * " (without spaces) as suggested somewhere else. Also tried AddFlags (ActivityFlags.GrantReadUriPermission);
As it works with a single attachment, I know the URIs are valid for sure...
I'd really need help.