Xamarin iOS-如何发送电子邮件 [英] Xamarin iOS - How to send emails
本文介绍了Xamarin iOS-如何发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试了以下教程: http://developer.xamarin .com / recipes / ios / shared_resources / email / send_an_email /
但是当我运行代码时,它从不输入CanSendMail总是命中Else语句。
But when I run the code it never enters CanSendMail always hits the Else statement.
代码
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);
}
}
有人可以帮我吗?
谢谢
推荐答案
我只需要在设备设置中启用电子邮件帐户
I just needed to enable an Email account within the devices settings.
这篇关于Xamarin iOS-如何发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文