Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xamarin iOS-如何发送电子邮件_C#_Ios_Email_Xamarin - Fatal编程技术网

C# Xamarin iOS-如何发送电子邮件

C# Xamarin iOS-如何发送电子邮件,c#,ios,email,xamarin,C#,Ios,Email,Xamarin,我尝试了以下教程: 但是,当我运行代码时,它从未进入CanSendMail,它总是点击Else语句 代码 public partial class ContactController : BaseController { MFMailComposeViewController mailController; public ContactController() : base(null, null) { } public override

我尝试了以下教程:

但是,当我运行代码时,它从未进入CanSendMail,它总是点击Else语句

代码

public partial class ContactController : BaseController
{
    MFMailComposeViewController mailController;

    public ContactController()
        : base(null, null)
    {
    }

    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        View.BackgroundColor = UIColor.White;

        var title = new UILabel(new RectangleF(-110, 80, 320, 30));
        title.Font = UIFont.SystemFontOfSize(24.0f);
        title.TextAlignment = UITextAlignment.Center;
        title.TextColor = UIColor.Black;
        title.Text = "Contact";

        if (MFMailComposeViewController.CanSendMail)
        {

            mailController = new MFMailComposeViewController();

            // do mail operations here
            mailController.SetToRecipients(new string[] { "john@doe.com" });
            mailController.SetSubject("mail test");
            mailController.SetMessageBody("this is a test", false);

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

            this.PresentViewController(mailController, true, null);
        }
        else { Console.WriteLine("Email can't be sent"); }

        var body = new UILabel(new RectangleF(50, 120, 220, 100));
        body.Font = UIFont.SystemFontOfSize(12.0f);
        body.TextAlignment = UITextAlignment.Center;
        body.Lines = 0;
        body.Text = @"This is the content view controller.";

        View.Add(title);
        View.Add(body);
    }
}
谁能帮我一下吗


谢谢

我只需要在设备设置中启用电子邮件帐户。

设备是否启用了任何电子邮件帐户?因为我不经常使用它。谢谢@SKall,现在一切正常。