利用Mono Touch的MessageUI组件发送email

有不明白的地方欢迎入群  347636249  探讨
using System;
//
using MonoTouch.UIKit;
using MonoTouch.Foundation;
using MonoTouch.MessageUI; //邮件
using System.Drawing;

namespace GCForum
{
	public class MyTestVC :UIViewController
	{
		public MyTestVC ()
		{
		}

		private MFMailComposeViewController _mail;
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			this.View.BackgroundColor = UIColor.White;
			//导航栏
			this.NavigationItem.SetRightBarButtonItem (
				new UIBarButtonItem (UIBarButtonSystemItem.Add, (sender,args) => {
				if (MFMailComposeViewController.CanSendMail) {
					_mail = new MFMailComposeViewController ();
					_mail.SetToRecipients (new string[] {
						"[email protected]", "[email protected]"
					});
					_mail.SetCcRecipients (new string[] { "[email protected]" });
					_mail.SetBccRecipients (new string[] { "[email protected]" });

					_mail.SetMessageBody ("hello world", false);
					_mail.SetSubject ("test email");
					_mail.Finished += HandleMainFinished;

					this.PresentViewController (_mail, true, null);
				} else {
					Utils.Tools.Alert ("Mail Not Sent");
				}
			}), true);
		}

		void HandleMainFinished(object sender, MFComposeResultEventArgs e)
		{
			if (e.Result == MFMailComposeResult.Sent) {
				Utils.Tools.Alert ("Mail Sent");
			}
			e.Controller.DismissViewController (true, null);
		}

		//...

	}
}

你可能感兴趣的:(MessageUI)