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

标签 c# ios email xamarin

我尝试按照教程进行操作:http://developer.xamarin.com/recipes/ios/shared_resources/email/send_an_email/

但是当我运行代码时,它永远不会进入 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);
    }
}

有人可以帮我解决这个问题吗

谢谢

最佳答案

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

关于c# - Xamarin iOS - 如何发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29368654/

相关文章:

c# - 锁内锁

ios - Alamofire 服务器请求将整数参数转换为字符串

java - 将值从操作发送到未从操作重定向的 jsp

mysql - 使用 Postfix 配置通配符捕获所有电子邮件

c# - 不能将文本数据类型选为 DISTINCT,因为它不可比较

c# - Linq 将方法作为 lambda 表达式求值

c# - 有没有办法在 OData 中说 "Expand Everything"?

ios - 当我已经在 appDelegate.swift 中使用 google 登录时,如何将 facebook 登录集成到我的 ios 应用程序中?

objective-c - 调用方法时会发生什么?争论在哪里?

c# - 邮件消息类