gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 12:25:08 25 4
gpt4 key购买 nike

我尝试按照教程进行操作: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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com