示例#1
0
        static Intent CreateIntent(EmailMessage message)
        {
            var intent = new Intent(Intent.ActionSend);

            intent.SetType("message/rfc822");

            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.FullPath));
                }

                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 new NotImplementedInReferenceAssemblyException();
示例#3
0
 static async Task ComposeWithUrl(EmailMessage message)
 {
     var url   = GetMailToUri(message);
     var nsurl = NSUrl.FromString(url);
     await Launcher.PlatformOpenAsync(nsurl);
 }