Ejemplo n.º 1
0
 static async Task ComposeWithUrl(EmailMessage message)
 {
     var url   = GetMailToUri(message);
     var nsurl = NSUrl.FromString(url);
     await Launcher.PlatformOpenAsync(nsurl);
 }
Ejemplo n.º 2
0
        static Intent CreateIntent(EmailMessage message)
        {
            var action = (message?.Attachments?.Count ?? 0) switch
            {
                0 => Intent.ActionSendto,
                1 => Intent.ActionSend,
                _ => Intent.ActionSendMultiple
            };
            var intent = new Intent(action);

            if (action == Intent.ActionSendto)
            {
                intent.SetData(Uri.Parse("mailto:"));
            }
            else
            {
                intent.SetType(FileSystem.MimeTypes.EmailMessage);
            }

            if (!string.IsNullOrEmpty(message?.Body))
            {
                if (message.BodyFormat == EmailBodyFormat.Html)
                {
                    ISpanned html;
#if __ANDROID_24__
                    if (Platform.HasApiLevelN)
                    {
                        html = Html.FromHtml(message.Body, FromHtmlOptions.ModeLegacy);
                    }
                    else
#endif
                    {
#pragma warning disable CS0618 // Type or member is obsolete
                        html = Html.FromHtml(message.Body);
#pragma warning restore CS0618 // Type or member is obsolete
                    }
                    intent.PutExtra(Intent.ExtraText, html);
                }
                else
                {
                    intent.PutExtra(Intent.ExtraText, message.Body);
                }
            }
            if (!string.IsNullOrEmpty(message?.Subject))
            {
                intent.PutExtra(Intent.ExtraSubject, message.Subject);
            }
            if (message?.To?.Count > 0)
            {
                intent.PutExtra(Intent.ExtraEmail, message.To.ToArray());
            }
            if (message?.Cc?.Count > 0)
            {
                intent.PutExtra(Intent.ExtraCc, message.Cc.ToArray());
            }
            if (message?.Bcc?.Count > 0)
            {
                intent.PutExtra(Intent.ExtraBcc, message.Bcc.ToArray());
            }

            if (message?.Attachments?.Count > 0)
            {
                var uris = new List <IParcelable>();
                foreach (var attachment in message.Attachments)
                {
                    uris.Add(Platform.GetShareableFileUri(attachment));
                }

                if (uris.Count > 1)
                {
                    intent.PutParcelableArrayListExtra(Intent.ExtraStream, uris);
                }
                else
                {
                    intent.PutExtra(Intent.ExtraStream, uris[0]);
                }

                intent.AddFlags(ActivityFlags.GrantReadUriPermission);
            }

            return(intent);
        }
    }
 static Task PlatformComposeAsync(EmailMessage message) =>
 throw ExceptionUtils.NotSupportedOrImplementedException;