使用依赖关系服务从Xamarin.Forms应用发送电子邮件 [英] Send email from Xamarin.Forms app using Dependency Service

查看:181
本文介绍了使用依赖关系服务从Xamarin.Forms应用发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,出于调试目的和测试目的,我需要发送电子邮件.

In my app, for debugging purposes and testing purposes I need to send an email.

当发送它的类不包含PresentViewController的定义时,如何显示邮件控制器?用户在激发的警报中单击是"后,该类需要激发电子邮件应用程序.

How do I present the mail controller, when the class that sends it does not contain a definition for PresentViewController ? The class needs to fire off the email app after the user clicks "yes" from the alert which fires.

    public async Task<bool> SendEmail(Exception ex)
    {
        var result = await SendNotificationToRequestSendingEmail();

        if (result)
        {

            if (MFMailComposeViewController.CanSendMail)
            {
                mailController = new MFMailComposeViewController();

                mailController.SetToRecipients(new string[] { "test@one.com", "test@two.com" });
                mailController.SetSubject("Details");
                mailController.SetMessageBody($"Message: {ex.Message}" +
                                              $"Exception: {ex.ToString()}"
                                              , false);

                mailController.Finished += (object s, MFComposeResultEventArgs args) =>
                {
                    Console.WriteLine(args.Result.ToString());
                    args.Controller.DismissViewController(true, null);
                };

                this.PresentViewController(mailController, true, null); //this line causes the error
            }
        }

        return true;
    }

如何解决或解决此问题?这是从Xamarin表单页面调用的.

How can I fix this problem or get around it? This is called from a Xamarin Forms page.

推荐答案

请查看以下答案:

从Gmail中发送电子邮件Xamarin.Forms应用程序

除此之外,您也可以使用此NuGet软件包来做到这一点:

besides that you can also do it with this NuGet package:

https://www.nuget.org/packages/Xam.Plugins.信息/

这篇关于使用依赖关系服务从Xamarin.Forms应用发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆