Ejemplo n.º 1
0
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            
			// wire up the send-mail compose view controller
			sendButton.TouchUpInside += (sender, e) => {       
				if (MFMailComposeViewController.CanSendMail) {
            
					var to = new string[]{ "*****@*****.**" };

					if (MFMailComposeViewController.CanSendMail) {
						mailController = new MFMailComposeViewController ();
						mailController.SetToRecipients (to);
						mailController.SetSubject ("mail test");
						mailController.SetMessageBody ("this is a test", false);
						mailController.Finished += (object s, MFComposeResultEventArgs args) => {

							Console.WriteLine ("result: " + args.Result.ToString ()); // sent or cancelled

							BeginInvokeOnMainThread (() => {
								args.Controller.DismissViewController (true, null);
							});
						};
					}

					this.PresentViewController (mailController, true, null);
				} else {
					new UIAlertView("Mail not supported", "Can't send mail from this device", null, "OK");
				}
            };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens up the ios Email Controller with pre-populated values
        /// </summary>
        /// <param name="email">Email.</param>
        public void CreateEmail(Email email)
        {
            if (CanSendEmail())
            {
                var mailController = new MFMailComposeViewController();
                mailController.SetMessageBody(email.Body, email.IsHtml);
                mailController.SetSubject(email.Subject);
                mailController.SetToRecipients(email.ToAddresses.ToArray());

                if (email.CcAddresses != null && email.CcAddresses.Count > 0 && !string.IsNullOrWhiteSpace(email.CcAddresses[0]))
                {
                    //currently assuming there will only be 1 cc address, TODO: confirm this
                    mailController.SetCcRecipients(email.CcAddresses.ToArray());
                }

                if (!string.IsNullOrWhiteSpace(email.AttachmentFileLocation))
                {
                    UIImage image = new UIImage(email.AttachmentFileLocation);
                    mailController.AddAttachmentData(image.AsJPEG(), "image/jpeg", Path.GetFileName(email.AttachmentFileLocation));
                }

                mailController.Finished += (s, args) => args.Controller.DismissViewController(true, null);
                var rootViewController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                rootViewController.PresentViewController(mailController, true, null);
            }
            else
            {
                App.CurrentApp.MainPage.DisplayAlert("No Email App Available", "Unable to send email.", "OK");
            }
        }
Ejemplo n.º 3
0
        // http://stackoverflow.com/questions/24136464/access-viewcontroller-in-dependecyservice-to-present-mfmailcomposeviewcontroller/24159484#24159484
        public bool Email(string emailAddress)
        {
            if (MFMailComposeViewController.CanSendMail)
            {
                var composer = new MFMailComposeViewController();
                composer.SetToRecipients(new string[] { emailAddress });

                composer.Finished += (object sender, MFComposeResultEventArgs e) => {
//					if (completed != null)
//						completed (e.Result == MFMailComposeResult.Sent);
                    e.Controller.DismissViewController(true, null);
                };

                //Adapt this to your app structure
                var rootController = ((AppDelegate)(UIApplication.SharedApplication.Delegate)).Window.RootViewController.ChildViewControllers[0].ChildViewControllers[1].ChildViewControllers[0];
                var navcontroller  = rootController as UINavigationController;
                if (navcontroller != null)
                {
                    rootController = navcontroller.VisibleViewController;
                }
                rootController.PresentViewController(composer, true, null);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 4
0
        public void Show(string to = null, string subject = null, string body = null)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                Alert.ShowErrorBox("Email is not setup correctly on this device");
                return;
            }

            var mail = new MFMailComposeViewController();

            mail.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
            mail.Finished += delegate {
                mail.DismissViewController(true, null);
            };

            if (!string.IsNullOrEmpty(to))
            {
                mail.SetToRecipients(new string[] { to });
            }

            if (!string.IsNullOrEmpty(subject))
            {
                mail.SetSubject(subject);
            }

            if (!string.IsNullOrEmpty(body))
            {
                mail.SetMessageBody(body, true);
            }

            _c.PresentViewController(mail, true, null);
        }
Ejemplo n.º 5
0
            public void SendEmail()
            {
#if __ANDROID__
                var email = new Intent(Android.Content.Intent.ActionSend);
                email.PutExtra(Android.Content.Intent.ExtraEmail, "*****@*****.**");
                email.PutExtra(Android.Content.Intent.ExtraCc, new string[] { "*****@*****.**" });
                email.PutExtra(Android.Content.Intent.ExtraSubject, "Prueba Android");
                email.PutExtra(Android.Content.Intent.ExtraText, "Hello from Android...!");
                email.SetType("message/rfc822");
                return(email); StartActivity(email);
#endif

#if __IOS__
                if (MFMailComposeViewController.CanSendMail)
                {
                    MFMailComposeViewController mailController = new MFMailComposeViewController();
                    mailController.SetToRecipients(new string[] { "*****@*****.**" });
                    mailController.SetSubject("mail test");
                    mailController.SetMessageBody("this is a test", false);
                    GetController().PresentViewController(mailController, true, null);
                    mailController.Finished += (object s, MFComposeResultEventArgs args) =>
                    {
                        Console.WriteLine(args.Result.ToString());
                        args.Controller.DismissViewController(true, null);
                    };
                    return(null);
                }
#endif
            }
Ejemplo n.º 6
0
        public static void Compose(string url)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                return;
            }

            MailTo mailTo = MailTo.ParseUrl(url);

            var mailComposer = new MFMailComposeViewController();

            mailComposer.MailComposeDelegate = new MailComposeDelegate();
            mailComposer.SetToRecipients(mailTo.EmailTo.ToArray());
            mailComposer.SetSubject(mailTo.EmailSubject);
            mailComposer.SetMessageBody(mailTo.EmailBody, true);

            foreach (var attachment in mailTo.EmailAttachments)
            {
                string path = attachment.Filename;
                if (!File.Exists(path))
                {
                    path = Path.Combine(TouchFactory.Instance.DataPath, attachment.Filename);
                }

                NSData data = NSData.FromFile(path);
                if (data != null)
                {
                    mailComposer.AddAttachmentData(data, attachment.MimeType, attachment.Filename);
                }
            }

            ModalManager.EnqueueModalTransition(TouchFactory.Instance.TopViewController, mailComposer, true);
        }
Ejemplo n.º 7
0
 void SendToEmail(string title, string text, string attachment, Action onSuccess, Action onFail)
 {
     if (MFMailComposeViewController.CanSendMail)
     {
         MFMailComposeViewController c = new MFMailComposeViewController();
         c.SetSubject(title);
         c.SetToRecipients(new string[] { _settings.DevelopersEmail });
         c.SetMessageBody(text, false);
         NSData data = new NSString(attachment).DataUsingEncoding(NSStringEncoding.UTF8);
         c.AddAttachmentData(data, "text/xml", "info.xml");
         _application.RootController.PresentViewController(c, true, null);
         c.Finished += (object sender, MFComposeResultEventArgs e) => {
             if (e.Result == MFMailComposeResult.Sent)
             {
                 onSuccess();
             }
             else
             {
                 onFail();
             }
             e.Controller.DismissViewController(true, null);
         };
     }
     else
     {
         UIAlertView alert = new UIAlertView("Cannot send report", "E-mail messages not allowed", null, "OK");
         alert.Show();
     }
 }
Ejemplo n.º 8
0
        public Task <MailResult> Send(string recipient, string subject, string message)
        {
            var tcs = new TaskCompletionSource <MailResult>();

            if (!MFMailComposeViewController.CanSendMail)
            {
                var mailResult = new MailResult(
                    false,
                    Resources.NoEmailErrorTitle,
                    Resources.NoEmailErrorMessage);
                return(Task.FromResult(mailResult));
            }

            var mailComposeViewController = new MFMailComposeViewController();

            mailComposeViewController.SetToRecipients(new[] { recipient });
            mailComposeViewController.SetSubject(subject);
            mailComposeViewController.SetMessageBody(message, false);

            mailComposeViewController.Finished += (sender, e) => {
                mailComposeViewController.DismissViewController(true, null);
                var mailResult = e.Result == MFMailComposeResult.Sent
                                  ? MailResult.Ok
                                  : new MailResult(false, null, null);
                tcs.SetResult(mailResult);
            };

            topViewControllerProvider.TopViewController.PresentViewController(mailComposeViewController, true, null);

            return(tcs.Task);
        }
Ejemplo n.º 9
0
        private void EmailButtonTouchDown(object sender, EventArgs e)
        {
            if (File.Exists(Settings.Current.LogFile))
            {
                if (MFMailComposeViewController.CanSendMail)
                {
                    NSData data = NSData.FromFile(Settings.Current.LogFile);

                    MFMailComposeViewController mailController = new MFMailComposeViewController();
                    mailController.SetSubject("Really simple iPhone error report");
                    mailController.SetToRecipients(new string[] { "*****@*****.**" });
                    mailController.SetMessageBody("Really simple error report", false);
                    mailController.AddAttachmentData(data, "text/plain", "error.log");
                    mailController.Finished += HandleMailFinished;
                    this.PresentModalViewController(mailController, true);
                }
                else
                {
                    ModalDialog.Alert("No email account found", "Please configure an email account before sending an error report");
                }
            }
            else
            {
                ModalDialog.Alert("No log file was found", "The error log was empty. Please try sending this again after the error occurs.");
            }
        }
Ejemplo n.º 10
0
        public void SendFeedbackErrorLog(string supportEmail, string subject)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                var av = new UIAlertView(Localize.GetValue("PanelMenuViewReportProblemText"), Localize.GetValue("ServiceError_EmailClientAbsent"), null, Localize.GetValue("OkButtonText"), null);
                av.Show();
                return;
            }

            var mailComposer = new MFMailComposeViewController();
            var logFile      = _logger.GetLogFileName();

            if (logFile != null)
            {
                mailComposer.AddAttachmentData(NSData.FromFile(logFile), "text", Path.GetFileName(logFile));
            }

            mailComposer.SetToRecipients(new [] { supportEmail });
            mailComposer.SetMessageBody("", false);
            mailComposer.SetSubject(subject);
            mailComposer.Finished += (sender, args) =>
            {
                var uiViewController = sender as UIViewController;
                if (uiViewController == null)
                {
                    throw new ArgumentException("sender");
                }

                uiViewController.DismissViewController(true, () => { });
                _modalHost.NativeModalViewControllerDisappearedOnItsOwn();
            };
            _modalHost.PresentModalViewController(mailComposer, true);
        }
Ejemplo n.º 11
0
        public void Email(string message, string subject, string[] recivers)
        {
            if (!MFMailComposeViewController.CanSendMail) {
                return;
            }
            MFMailComposeViewController mailController = new MFMailComposeViewController();
            if (!MFMailComposeViewController.CanSendMail)
            {
                return;
            }
            if (recivers != null)
            {
                mailController.SetToRecipients(recivers);
            }
            mailController.SetSubject(subject);
            mailController.SetMessageBody(message, false);
            mailController.Finished += ( s, args) =>
            {

                if(fromScreen==Screen.ContactList)
                {
                    c_ViewController.DismissViewController(true,null);
                    c_ViewController.NavigationController.PopViewController(false);
                }
                else{
                    c_ViewController.DismissViewController(true,null);
                }
            };

            c_ViewController.PresentViewController(mailController, true, null);
        }
Ejemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        // create some arbitary binary data. or load from existing location
        FileStream someFile = new FileStream(Application.temporaryCachePath + "/someFile.bin", FileMode.Create);

        someFile.WriteByte(0x42);
        someFile.Close();

        _mailController = new MFMailComposeViewController();

        _mailControllerDelegate             = new MyMFMailComposeViewControllerDelegate();
        _mailController.mailComposeDelegate = _mailControllerDelegate;

        _mailController.SetToRecipients(new string[] { "*****@*****.**" });
        _mailController.SetSubject("well hello");
        _mailController.SetMessageBody("just testing attachments", false);

        _mailController.AddAttachmentData(
            new NSData(Application.temporaryCachePath + "/someFile.bin"),
            "application/octet-stream",
            "someFile.bin"
            );

        UIApplication.deviceRootViewController.PresentViewController(_mailController, true, null);
    }
Ejemplo n.º 13
0
        public void ComposeEmail(
            IEnumerable <string> to, IEnumerable <string> cc = null, string subject = null,
            string body = null, bool isHtml = false,
            IEnumerable <EmailAttachment> attachments = null, string dialogTitle = null)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                throw new MvxException("This device cannot send mail");
            }

            _mail = new MFMailComposeViewController();
            _mail.SetMessageBody(body ?? string.Empty, isHtml);
            _mail.SetSubject(subject ?? string.Empty);

            if (cc != null)
            {
                _mail.SetCcRecipients(cc.ToArray());
            }

            _mail.SetToRecipients(to?.ToArray() ?? new[] { string.Empty });
            if (attachments != null)
            {
                foreach (var a in attachments)
                {
                    _mail.AddAttachmentData(NSData.FromStream(a.Content), a.ContentType, a.FileName);
                }
            }
            _mail.Finished += HandleMailFinished;

            _modalHost.PresentModalViewController(_mail, true);
        }
Ejemplo n.º 14
0
		/// <summary>
		/// Shows the draft.
		/// </summary>
		/// <param name="subject">The subject.</param>
		/// <param name="body">The body.</param>
		/// <param name="html">if set to <c>true</c> [HTML].</param>
		/// <param name="to">To.</param>
		/// <param name="cc">The cc.</param>
		/// <param name="bcc">The BCC.</param>
		/// <param name="attachments">The attachments.</param>
		public void ShowDraft(
			string subject,
			string body,
			bool html,
			string[] to,
			string[] cc,
			string[] bcc,
			IEnumerable<string> attachments = null)
		{
			var mailer = new MFMailComposeViewController();

			mailer.SetMessageBody(body ?? string.Empty, html);
			mailer.SetSubject(subject ?? string.Empty);
			mailer.SetCcRecipients(cc);
			mailer.SetToRecipients(to);
			mailer.Finished += (s, e) => ((MFMailComposeViewController)s).DismissViewController(true, () => { });

			if (attachments != null) 
			{
				foreach (var attachment in attachments) 
				{
					mailer.AddAttachmentData (NSData.FromFile (attachment), GetMimeType (attachment), Path.GetFileName (attachment));
				}
			}

			UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
		}
Ejemplo n.º 15
0
        public Task OpenEmailManager(string[] emails, string subject, string text, string[] attachments)
        {
            var tcs = new TaskCompletionSource <bool>();

            if (MFMailComposeViewController.CanSendMail)
            {
                var c = new MFMailComposeViewController();
                c.SetToRecipients(emails);
                c.SetSubject(subject ?? "");
                c.SetMessageBody(text ?? "", false);
                foreach (string attachment in attachments)
                {
                    NSData data = NSData.FromFile(attachment);
                    if (data != null)
                    {
                        c.AddAttachmentData(data, GetMimeType(attachment), Path.GetFileName(attachment));
                    }
                }

                _application.RootController.PresentViewController(c, true, null);
                c.Finished += (sender, e) =>
                {
                    tcs.SetResult(e.Result == MFMailComposeResult.Sent);
                    _application.InvokeOnMainThread(() => e.Controller.DismissViewController(true, null));
                };
            }
            else
            {
                var alert = new UIAlertView("Cannot send report", "E-mail messages not allowed", null, "OK");
                alert.Clicked += (sender, args) => tcs.SetResult(false);
                alert.Show();
            }
            return(tcs.Task);
        }
Ejemplo n.º 16
0
        public void SendEmail(string toEmail, string subject = null, string text = null)
        {
            if (MFMailComposeViewController.CanSendMail)
            {
                var mailController = new MFMailComposeViewController();

                if (!string.IsNullOrEmpty(toEmail))
                {
                    mailController.SetToRecipients(toEmail.Split(new[] { ',', ';', ' ' },
                                                                 StringSplitOptions.RemoveEmptyEntries));
                }

                if (!string.IsNullOrEmpty(subject))
                {
                    mailController.SetSubject(subject);
                }

                if (!string.IsNullOrEmpty(text))
                {
                    mailController.SetMessageBody(text, false);
                }

                mailController.Finished += (sender, args) =>
                {
                    var controller = (MFMailComposeViewController)sender;
                    controller.InvokeOnMainThread(() => controller.DismissViewController(true, null));
                };

                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailController, true,
                                                                                                   null);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Shows the draft.
        /// </summary>
        /// <param name="subject">The subject.</param>
        /// <param name="body">The body.</param>
        /// <param name="html">if set to <c>true</c> [HTML].</param>
        /// <param name="to">To.</param>
        /// <param name="cc">The cc.</param>
        /// <param name="bcc">The BCC.</param>
        /// <param name="attachments">The attachments.</param>
        public void ShowDraft(
            string subject,
            string body,
            bool html,
            string[] to,
            string[] cc,
            string[] bcc,
            IEnumerable <string> attachments = null)
        {
            var mailer = new MFMailComposeViewController();

            mailer.SetMessageBody(body ?? string.Empty, html);
            mailer.SetSubject(subject ?? string.Empty);
            mailer.SetCcRecipients(cc);
            mailer.SetToRecipients(to);
            mailer.Finished += (s, e) => ((MFMailComposeViewController)s).DismissViewController(true, () => { });

            if (attachments != null)
            {
                foreach (var attachment in attachments)
                {
                    mailer.AddAttachmentData(NSData.FromFile(attachment), GetMimeType(attachment), Path.GetFileName(attachment));
                }
            }

            UIViewController vc = UIApplication.SharedApplication.KeyWindow.RootViewController;

            while (vc.PresentedViewController != null)
            {
                vc = vc.PresentedViewController;
            }
            vc.PresentViewController(mailer, true, null);
        }
Ejemplo n.º 18
0
        void ISimpleEmailPlugin.SendEmail(string toEmail, string subject, string message)
        {
            if (_vc == null)
            {
                throw new MissingMethodException("You have to call Init() method before");
            }

            if (MFMailComposeViewController.CanSendMail)
            {
                var to = new string[] { toEmail };

                if (MFMailComposeViewController.CanSendMail)
                {
                    _mailController = new MFMailComposeViewController();
                    _mailController.SetToRecipients(to);
                    _mailController.SetSubject(subject);
                    _mailController.SetMessageBody(message, false);
                    _mailController.Finished += (object s, MFComposeResultEventArgs args) => {
                        _vc.BeginInvokeOnMainThread(() => {
                            args.Controller.DismissViewController(true, null);
                        });
                    };
                }

                _vc.PresentViewController(_mailController, true, null);
            }
            else
            {
                new UIAlertView("Can't send email", string.Empty, null, "OK").Show();
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            // HTML is perfect to display this kind of content.
            this.webView.LoadData (NSData.FromFile ("about.html"), "text/html", "UTF8", NSUrl.FromString ("."));

            //  We want to open links in the real Safari and mailto links should also be handled correctly.
            this.webView.ShouldStartLoad = (webView, request, navigationType) => {

                // If a "mailto:" link is clicked, open a mail composition sheet.
                if(request.Url.AbsoluteString.StartsWith("mailto:"))
                {
                    string recipient = request.Url.AbsoluteString.Replace("mailto:", "");
                    var mail = new MFMailComposeViewController();
                    mail.SetToRecipients(new[] { recipient });
                    mail.SetSubject("MultiMode LED");
                    mail.Finished += (sender, e) => ((MFMailComposeViewController)sender).DismissViewController(true, null);
                    this.PresentViewController(mail, true, null);
                    return false;
                }

                // For other links, open Safari.
                if(navigationType == UIWebViewNavigationType.LinkClicked)
                {
                    UIApplication.SharedApplication.OpenUrl(request.Url);
                    return false;
                }
                return true;
            };
        }
        private void SendButton_TouchUpInside(object sender, EventArgs e)
        {
            if (MFMailComposeViewController.CanSendMail)
            {
                // an array of strings that represents recipients
                var to = new string[] { "*****@*****.**" };

                // MFMailComposeViewController calls the UI to send an email
                if (MFMailComposeViewController.CanSendMail)
                {
                    mailController = new MFMailComposeViewController();
                    mailController.SetToRecipients(to);
                    mailController.SetSubject("A picture");
                    mailController.SetMessageBody("Hi, I'm sending a picture from iOS", false);

                    mailController.AddAttachmentData(ImageView.Image.AsJPEG(), "image/jpeg", "image.jpg");

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

                this.PresentViewController(mailController, true, null);
            }
        }
        public void ComposeEmail(
            IEnumerable<string> to, IEnumerable<string> cc = null, string subject = null,
            string body = null, bool isHtml = false,
            IEnumerable<EmailAttachment> attachments = null, string dialogTitle = null)
        {
            if (!MFMailComposeViewController.CanSendMail)
                throw new MvxException("This device cannot send mail");

            _mail = new MFMailComposeViewController();
            _mail.SetMessageBody(body ?? string.Empty, isHtml);
            _mail.SetSubject(subject ?? string.Empty);

            if (cc != null)
                _mail.SetCcRecipients(cc.ToArray());

            _mail.SetToRecipients(to?.ToArray() ?? new[] { string.Empty });
            if (attachments != null)
            {
                foreach (var a in attachments)
                {
                    _mail.AddAttachmentData(NSData.FromStream(a.Content), a.ContentType, a.FileName);
                }
            }
            _mail.Finished += HandleMailFinished;

            _modalHost.PresentModalViewController(_mail, true);
        }
Ejemplo n.º 22
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // wire up the send-mail compose view controller
            sendButton.TouchUpInside += (sender, e) => {
                if (MFMailComposeViewController.CanSendMail)
                {
                    var to = new string[] { "*****@*****.**" };

                    if (MFMailComposeViewController.CanSendMail)
                    {
                        mailController = new MFMailComposeViewController();
                        mailController.SetToRecipients(to);
                        mailController.SetSubject("mail test");
                        mailController.SetMessageBody("this is a test", false);
                        mailController.Finished += (object s, MFComposeResultEventArgs args) => {
                            Console.WriteLine("result: " + args.Result.ToString());                               // sent or cancelled

                            BeginInvokeOnMainThread(() => {
                                args.Controller.DismissViewController(true, null);
                            });
                        };
                    }

                    this.PresentViewController(mailController, true, null);
                }
                else
                {
                    new UIAlertView("Mail not supported", "Can't send mail from this device", null, "OK");
                }
            };
        }
Ejemplo n.º 23
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            if (MFMailComposeViewController.CanSendMail)
            {
                var mailController = new MFMailComposeViewController();
                mailController.SetToRecipients(new[] {
                        "*****@*****.**"
                    });
                mailController.SetSubject("This seems to work :)");
                mailController.SetMessageBody("Lorem ipsum", false);
                mailController.Finished += (sender, e) =>
                {
                    this.DismissViewController(true, null);
                };
                this.PresentViewController(mailController, true, null);
            }
            else
            {
                var alert = UIAlertController.Create("Mail sending disabled", "It seems this device can't send mail!", UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                this.PresentViewController(alert, true, null);
            }
        }
Ejemplo n.º 24
0
        public Task OpenEmailManager(string[] emails, string subject, string text, string[] attachments)
        {
            var tcs = new TaskCompletionSource<bool>();
            if (MFMailComposeViewController.CanSendMail)
            {
                var c = new MFMailComposeViewController();
                c.SetToRecipients(emails);
                c.SetSubject(subject ?? "");
                c.SetMessageBody(text ?? "", false);
                foreach (string attachment in attachments)
                {
                    NSData data = NSData.FromFile(attachment);
                    if (data != null)
                        c.AddAttachmentData(data, GetMimeType(attachment), Path.GetFileName(attachment));
                }

                _application.RootController.PresentViewController(c, true, null);
                c.Finished += (sender, e) =>
                {
                    tcs.SetResult(e.Result == MFMailComposeResult.Sent);
                    _application.InvokeOnMainThread(() => e.Controller.DismissViewController(true, null));
                };
            }
            else
            {
                var alert = new UIAlertView("Cannot send report", "E-mail messages not allowed", null, "OK");
                alert.Clicked += (sender, args) => tcs.SetResult(false);
                alert.Show();
            }
            return tcs.Task;
        }
Ejemplo n.º 25
0
 public Task<bool> SendReport(IReport report)
 {
     var tcs = new TaskCompletionSource<bool>();
     if (MFMailComposeViewController.CanSendMail)
     {
         var c = new MFMailComposeViewController();
         c.SetSubject(report.Title);
         c.SetToRecipients(new[] {_settings.DevelopersEmail});
         c.SetMessageBody(report.Body, false);
         NSData data = new NSString(report.Attachment).DataUsingEncoding(NSStringEncoding.UTF8);
         c.AddAttachmentData(data, "text/xml", "info.xml");
         _application.RootController.PresentViewController(c, true, null);
         c.Finished += (sender, e) =>
         {
             tcs.SetResult(e.Result == MFMailComposeResult.Sent);
             e.Controller.DismissViewController(true, null);
         };
     }
     else
     {
         var alert = new UIAlertView("Cannot send report", "E-mail messages not allowed", null, "OK");
         alert.Clicked += (sender, args) => tcs.SetResult(false);
         alert.Show();
     }
     return tcs.Task;
 }
Ejemplo n.º 26
0
        public void CreateEmail(List <string> emailAddresses, List <string> ccs, string subject, string body, string htmlBody)
        {
            var vc = new MFMailComposeViewController();

            vc.MailComposeDelegate = this;

            if (emailAddresses?.Count > 0)
            {
                vc.SetToRecipients(emailAddresses.ToArray());
            }

            if (ccs?.Count > 0)
            {
                vc.SetCcRecipients(ccs.ToArray());
            }

            vc.SetSubject(subject);
            vc.SetMessageBody(htmlBody, true);
            vc.Finished += (sender, e) =>
            {
                vc.DismissModalViewController(true);
            };



            UIApplication.SharedApplication.Windows[0].
            RootViewController.PresentViewController(vc, true, null);
        }
        // This function builds email confirmation with attachment
        private void SendEmail(string[] recipients, string messageBody, UIImage attachment)
        {
            try
            {
                var d = new MFMessageComposeViewController();

                var mailController = new MFMailComposeViewController();

                mailController.SetToRecipients(recipients);
                mailController.SetSubject("Email Confirmation By Just Delivered");
                mailController.SetMessageBody(messageBody, false);
                mailController.AddAttachmentData(attachment.AsJPEG(), "image/png", "photo.png");

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

                this.PresentViewController(d, true, null);
            }
            catch (FeatureNotSupportedException ex)
            {
                myPage.DisplayException(ex.Message);
            }
            catch (Exception ex)
            {
                myPage.DisplayException(ex.Message);
            }
        }
Ejemplo n.º 28
0
        public void SendEmail(string email, string title)
        {
            if (MFMailComposeViewController.CanSendMail) {
                try {
                    if (validator.isEmail (email)) {
                        mailController.SetToRecipients (new string[]{ email });
                    }

                    if(!string.IsNullOrEmpty(title)){
                        mailController.SetSubject (title);

                    }
                    //_mailController.SetMessageBody ("this is a test", false);
                    mailController.Finished += ( object s, MFComposeResultEventArgs args) => {
                        Console.WriteLine (args.Result.ToString ());
                        RootController.NavigationBarHidden = false;
                        RootController.ToolbarHidden = false;
                        args.Controller.DismissViewController (true, null);
                    };
                    RootController.PresentViewController(mailController, true, null);

                } catch (Exception exp) {
                    Console.WriteLine (exp.Message);

                }
            }
        }
Ejemplo n.º 29
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            if (MFMailComposeViewController.CanSendMail)
            {
                var mailController = new MFMailComposeViewController();
                mailController.SetToRecipients(new[] {
                    "*****@*****.**"
                });
                mailController.SetSubject("This seems to work :)");
                mailController.SetMessageBody("Lorem ipsum", false);
                mailController.Finished += (sender, e) =>
                {
                    this.DismissViewController(true, null);
                };
                this.PresentViewController(mailController, true, null);
            }
            else
            {
                var alert = UIAlertController.Create("Mail sending disabled", "It seems this device can't send mail!", UIAlertControllerStyle.Alert);
                alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
                this.PresentViewController(alert, true, null);
            }
        }
Ejemplo n.º 30
0
        public void sendEmail()
        {
            MFMailComposeViewController mailController;

            if (MFMailComposeViewController.CanSendMail)
            {
                // do mail operations here

                //Set the recipients, subject and message body
                mailController = new MFMailComposeViewController();
                mailController.SetToRecipients(new string[] { App.DAUtil.GetUser().ElementAt(0).emailadd });
                mailController.SetSubject("Raport OMIKAS");
                mailController.SetMessageBody("Raport programu OMIKAS", false);

                //Handle the Finished event.
                mailController.Finished += (object s, MFComposeResultEventArgs args) =>
                {
                    Console.WriteLine(args.Result.ToString());
                    args.Controller.DismissViewController(true, null);
                };
                //zalaczyc zalacznik i poprawic bledy

                //Present the MFMailComposeViewController. - linijka nizej powinna dzialac coz.
                //this.PresentViewController(mailController, true, null);
            }
        }
Ejemplo n.º 31
0
    public override void ShowDraft(
        string subject,
        string body,
        bool html,
        string[] to,
        string[] cc,
        string[] bcc,
        byte[] screenshot = null)
    {
        var mailer = new MFMailComposeViewController();

        mailer.SetMessageBody(body ?? string.Empty, html);
        mailer.SetSubject(subject ?? string.Empty);
        mailer.SetCcRecipients(cc);
        mailer.SetToRecipients(to);
        mailer.Finished += (s, e) => ((MFMailComposeViewController)s).DismissViewController(true, () => { });
        if (screenshot != null)
        {
            mailer.AddAttachmentData(NSData.FromArray(screenshot), "image/png", "screenshot.png");
        }
        UIViewController vc = UIApplication.SharedApplication.KeyWindow.RootViewController;

        while (vc.PresentedViewController != null)
        {
            vc = vc.PresentedViewController;
        }
        vc.PresentViewController(mailer, true, null);
    }
Ejemplo n.º 32
0
        public void Show(string to = null, string subject = null, string body = null)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                Alert.ShowErrorBox("Email is not setup correctly on this device");
                return;
            }

            var mail = new MFMailComposeViewController ();
            mail.ModalPresentationStyle = UIModalPresentationStyle.FormSheet;
            mail.Finished += delegate {
                mail.DismissViewController(true, null);
            };

            if (!string.IsNullOrEmpty(to))
                mail.SetToRecipients(new string[] { to });

            if (!string.IsNullOrEmpty (subject))
                mail.SetSubject (subject);

            if (!string.IsNullOrEmpty (body))
                mail.SetMessageBody (body, true);

            _c.PresentViewController(mail, true, null);
        }
Ejemplo n.º 33
0
        public void SendEmail(string[] toRecipients, string subject, string text = null, FileUri[] attachments = null)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                throw new InvalidOperationException("System can not send email.");
            }

            MFMailComposeViewController mailController = new MFMailComposeViewController();

            mailController.SetToRecipients(toRecipients);
            mailController.SetSubject(subject);
            mailController.SetMessageBody(text, false);
            mailController.Finished += (sender, e) => ((UIViewController)sender).DismissViewController(true, null);

            if (attachments != null &&
                attachments.Length > 0)
            {
                attachments
                .ToList()
                .ForEach(a =>
                {
                    mailController.AddAttachmentData(
                        NSData.FromUrl(a.ToNSUrl()),
                        "application/octet-stream",
                        Path.GetFileName(a.AbsolutePath));
                });
            }

            UIApplication.SharedApplication
            .Windows[0]
            .RootViewController
            .PresentViewController(mailController, true, null);
        }
Ejemplo n.º 34
0
        public Task <bool> SendReport(IReport report)
        {
            var tcs = new TaskCompletionSource <bool>();

            if (MFMailComposeViewController.CanSendMail)
            {
                var c = new MFMailComposeViewController();
                c.SetSubject(report.Title);
                c.SetToRecipients(new[] { _settings.DevelopersEmail });
                c.SetMessageBody(report.Body, false);
                NSData data = new NSString(report.Attachment).DataUsingEncoding(NSStringEncoding.UTF8);
                c.AddAttachmentData(data, "text/xml", "info.xml");
                _application.RootController.PresentViewController(c, true, null);
                c.Finished += (sender, e) =>
                {
                    tcs.SetResult(e.Result == MFMailComposeResult.Sent);
                    e.Controller.DismissViewController(true, null);
                };
            }
            else
            {
                var alert = new UIAlertView("Cannot send report", "E-mail messages not allowed", null, "OK");
                alert.Clicked += (sender, args) => tcs.SetResult(false);
                alert.Show();
            }
            return(tcs.Task);
        }
Ejemplo n.º 35
0
        public void ComposeMail(string[] recipients, string subject, string messagebody = null, Action <bool> completed = null)
        {
            if (MFMailComposeViewController.CanSendMail)
            {
                var controller = new MFMailComposeViewController();
                controller.SetToRecipients(recipients);
                controller.SetSubject(subject);
                if (!string.IsNullOrEmpty(messagebody))
                {
                    controller.SetMessageBody(messagebody, false);
                }
                controller.Finished += (object sender, MFComposeResultEventArgs e) => {
                    if (completed != null)
                    {
                        completed(e.Result == MFMailComposeResult.Sent);
                    }
                    e.Controller.DismissViewController(true, null);
                };

                //Adapt this to your app structure
                //var rootController = ((AppDelegate)(UIApplication.SharedApplication.Delegate)).Window.RootViewController.ChildViewControllers[0].ChildViewControllers[1].ChildViewControllers[0];
                var rootController = UIApplication.SharedApplication.KeyWindow.RootViewController;
                var navcontroller  = rootController as UINavigationController;
                if (navcontroller != null)
                {
                    rootController = navcontroller.VisibleViewController;
                }
                rootController.PresentViewController(controller, true, null);
            }
        }
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            
            // Perform any additional setup after loading the view, typically from a nib.
            
            button = UIButton.FromType (UIButtonType.RoundedRect);
            button.Frame = new CGRect (10, 10, 100, 44);
            button.SetTitle ("Send Email", UIControlState.Normal);
            View.AddSubview (button);
			to = new string[]{ "*****@*****.**" };

			if (MFMailComposeViewController.CanSendMail) {
				mailController = new MFMailComposeViewController ();
				mailController.SetToRecipients (to);
				mailController.SetSubject ("mail test");
				mailController.SetMessageBody ("this is a test", false);
				mailController.Finished += ( object s, MFComposeResultEventArgs args) => {
                
					Console.WriteLine (args.Result.ToString ());
                
					BeginInvokeOnMainThread (() => {
						args.Controller.DismissViewController (true, null);
					});
				};
			}
            button.TouchUpInside += (sender, e) => {       
				if (MFMailComposeViewController.CanSendMail) {
                	this.PresentViewController (mailController, true, null);
				} else {
					new UIAlertView("Mail not supported", "Can't send mail from this device", null, "OK");
				}
            };
        }
Ejemplo n.º 37
0
        /// <summary>
        /// Shows the native MFMailComposeViewController to send an email.
        /// Raises MailCompleted event when completed.</summary>
        ///
        /// <param name="recipients"> An array of strings representing the email addresses of the recipients.</param>
        /// <param name="subject"> The subject of the email.</param>
        /// <param name="body"> The body of the email.</param>
        /// <param name="bodyIsHTML"> True if the body is HTML; false otherwise.</param>
        /// <param name="image"> The image to attach to the email.</param>
        /// <param name="checkServiceAvailable"> Whether to check if the service is available first.</param>
        /// <returns> True if it is able to show the native view controller; false if it cannot send email.</returns>
        public static bool Mail(string[] recipients, string subject, string body, bool bodyIsHTML, UIImage image, bool checkServiceAvailable)
        {
            if (checkServiceAvailable && !MFMailComposeViewController.CanSendMail())
            {
                return(false);
            }

            var vc = new MFMailComposeViewController();

            if (vc.IsNil)
            {
                return(false);
            }

            vc.mailComposeDelegate = MailComposeViewControllerDelegate.instance;
            vc.SetToRecipients(recipients);
            vc.SetSubject(subject);
            vc.SetMessageBody(body, bodyIsHTML);

            if (image != null)
            {
                var nsdata = image.PNGRepresentation();
                vc.AddAttachmentData(nsdata, "image/png", "image.png");
            }

            UIApplication.deviceRootViewController.PresentViewController(vc, true, null);
            return(true);
        }
Ejemplo n.º 38
0
        public Bullying() : base(UITableViewStyle.Grouped, null)
        {
            Title            = NSBundle.MainBundle.LocalizedString("Bullying", "Bullying");
            TabBarItem.Image = UIImage.FromBundle("bullying");
//			var HelpButton = new UIButton(UIButtonType.RoundedRect);
//			HelpButton.SetTitle("Help Me!", UIControlState.Normal);
            Root = new RootElement("Student Guide")
            {
                new Section("Bullying")
                {
                    new StyledStringElement("Help me!", () => {
                        //AppDelegate.getControl.calling(); //Phones a number all like 'SAVE ME PLS'
                    })
                    {
                        TextColor = UIColor.Red,
                    },
                    new RootElement("Speak Up!")
                    {
                        new Section("Speak up form")
                        {
                            (FullName = new EntryElement("Full Name", "Full Name", "")),
                            (Incident = new EntryElement("Incedent", "Incedent", "", false)),
                            (Location = new EntryElement("Location of Incident", "Location of Incident", "")),
                            (ThoseInvolved = new EntryElement("Persons Involved", "Persons Involved", "")),
                        },
                        new Section()
                        {
                            new StringElement("Submit", delegate {
                                UIAlertView popup = new UIAlertView("Alert", "Do you wish to send an Email, a Text or cancel the form?", null, "Cancel", "Text", "Email");
                                popup.Show();
                                popup.Dismissed += delegate(object sender, UIButtonEventArgs e) {
                                    if (e.ButtonIndex == 1)
                                    {
                                        MFMessageComposeViewController msg = new MFMessageComposeViewController();
                                        msg.Recipients = new string[] { "07624808747" };
                                        msg.Body       = "Hello, I am being bullied by " + ThoseInvolved.Value + " they were " + Incident.Value + " this all happened " + Location.Value + "" + Environment.NewLine + "" + FullName.Value;
                                        this.NavigationController.PresentViewController(msg, true, null);
                                    }
                                    else if (e.ButtonIndex == 2)
                                    {
                                        MFMailComposeViewController email = new MFMailComposeViewController();
                                        email.SetSubject("Help me i'm being bullied");
                                        email.SetToRecipients(new string[] { "*****@*****.**" });
                                        email.SetMessageBody("Hello, I am being bullied by " + ThoseInvolved.Value + " they were " + Incident.Value + " this all happened " + Location.Value + "" + Environment.NewLine + "" + FullName.Value, false);
                                        this.NavigationController.PresentViewController(email, true, null);
                                    }
                                };
                            }),
                        },
                    },
                    new RootElement("Bullying Information")
                    {
                        from x in bullyingInfo
                        select(Section) Generate(x)
                    },
                }
            };
        }
Ejemplo n.º 39
0
 private void OpenMailer()
 {
     var mailer = new MFMailComposeViewController();
     mailer.SetSubject("AppreciateUI Feedback");
     mailer.SetToRecipients(new string[] { "*****@*****.**" });
     mailer.ModalPresentationStyle = UIModalPresentationStyle.PageSheet;
     mailer.Finished += (sender, e) => this.DismissViewController(true, null);
     this.PresentViewController(mailer, true, null);
 }
Ejemplo n.º 40
0
        public async Task ComposeEmail(string[] recipients, string mailSubject, string mailBody, string attachmentFilePath, string attachmentType, Action onSuccesfulSend, Action onFailedSend, Action onSendCancel)
        {
            if (MFMailComposeViewController.CanSendMail)
            {
                MFMailComposeViewController mailController = new MFMailComposeViewController();

                if (recipients != null && recipients.Length > 0)
                {
                    mailController.SetToRecipients(recipients);
                }
                if (!string.IsNullOrEmpty(mailSubject))
                {
                    mailController.SetSubject(mailSubject);
                }
                if (!string.IsNullOrEmpty(mailBody))
                {
                    mailController.SetMessageBody(mailBody, false);
                }

                if (!string.IsNullOrEmpty(attachmentFilePath))
                {
                    IFile attachmentFile = await FileSystem.Current.GetFileFromPathAsync(attachmentFilePath);

                    if (attachmentFile != null)
                    {
                        NSData attachmentData = NSData.FromFile(attachmentFilePath);
                        string mimeType       = attachmentType;
                        mailController.AddAttachmentData(attachmentData, mimeType, attachmentFile.Name);
                    }
                }

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

                    if (args.Result == MFMailComposeResult.Sent)
                    {
                        onSuccesfulSend?.Invoke();
                    }
                    else if (args.Result == MFMailComposeResult.Failed)
                    {
                        onFailedSend?.Invoke();
                    }
                    else
                    {
                        onSendCancel?.Invoke();
                    }
                };
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailController, true, null);
            }
            else
            {
                onFailedSend?.Invoke();
                throw new Exception("Error sending mail: No mail client has been configured on this device.");
            }
        }
Ejemplo n.º 41
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (_view != null)
            {
                _view.Dispose();
                _view = null;
            }

            // The piece detail view covers the whole screen, since it creates its own empty space semi-modally
            _view = new PieceDetailView(_piece, new RectangleF(
                                            0, 0,
                                            UIScreen.MainScreen.Bounds.Width,
                                            UIScreen.MainScreen.Bounds.Height
                                            ));
            _view.Parent = this;

            if (_view.BuyButton != null)
            {
                _view.BuyButton.TouchUpInside += (o, e) =>
                {
                    if (MFMailComposeViewController.CanSendMail)
                    {
                        _mail = new CustomMailer();
                        _mail.SetSubject("Purchase Inquiry");
                        _mail.SetMessageBody("Hi " + AppManifest.Current.FirstName + ",\r\n\r\nI would like to purchase your work titled '" + _piece.Title + "'.\r\n\r\nPlease let me know how I may do so.\r\n\r\nThanks!", false);
                        _mail.SetToRecipients(new string[] { AppManifest.Current.Email });
                        _mail.Finished += HandleMailFinished;

                        var controller = (CustomNavigationController)AppDelegate.NavigationController;

                        controller.PresentModalViewController(_mail, true);
                        _view.BuyButton.Cancel();
                    }
                    else
                    {
                        UIAlertView alert = new UIAlertView("Mail Alert", "Mail Unavailable", null, "Please try again later.", null);
                        alert.Show();
                        _view.BuyButton.Cancel();
                    }
                };
            }

            _view.PictureTapped += delegate
            {
                PushFullView();
            };

            _view.OffsideTapped += delegate
            {
                this.DismissSemiModalViewController(this);
            };

            View = _view;
        }
Ejemplo n.º 42
0
 private Element Generate(StudentGuideModel item)
 {
     var root=new RootElement(item.Title);
     var section=new Section(item.Title);
     root.Add (section);
     if (item.Phone!="") {
         var phoneStyle = new StyledStringElement("Contact Number",item.Phone) {
             BackgroundColor=UIColor.FromRGB(71,165,209),
             TextColor=UIColor.White,
             DetailColor=UIColor.White,
         };
         phoneStyle.Tapped+= delegate {
             UIAlertView popup = new UIAlertView("Alert","Do you wish to send a text or diall a number?",null,"Cancel","Text","Call");
             popup.Show();
             popup.Dismissed += delegate(object sender, UIButtonEventArgs e) {
                 if (e.ButtonIndex==1) {
                     MFMessageComposeViewController msg = new MFMessageComposeViewController();
                     msg.Recipients=new string[] {item.Phone};
                     this.NavigationController.PresentViewController(msg,true,null);
                 } else if (e.ButtonIndex==2) {
                     AppDelegate.getControl.calling(item.Phone);
                 };
             };
         };
         section.Add(phoneStyle);
     };
     if (item.Email!="") {
         var style = new StyledStringElement("Contact Email",item.Email) {
             BackgroundColor=UIColor.FromRGB(71,165,209),
             TextColor=UIColor.White,
             DetailColor=UIColor.White,
         };
         style.Tapped += delegate {
             MFMailComposeViewController email = new MFMailComposeViewController();
             email.SetToRecipients(new string[] {item.Email});
             this.NavigationController.PresentViewController(email,true,null);
         };
         section.Add (style);
     }
     if (item.Address!="") {
         section.Add(new StyledMultilineElement(item.Address) {
             BackgroundColor=UIColor.FromRGB(71,165,209),
             TextColor=UIColor.White,
             DetailColor=UIColor.White,
         });
     }
     if (item.Description!="") {
         section.Add (new StyledMultilineElement(item.Description) {
             BackgroundColor=UIColor.FromRGB(71,165,209),
             TextColor=UIColor.White,
             DetailColor=UIColor.White,
             Alignment=UITextAlignment.Center,
         });
     }
     return root;
 }
Ejemplo n.º 43
0
 private void SendMessage(object sender, EventArgs e)
 {
     if (MFMailComposeViewController.CanSendMail) {
         var mailController = new MFMailComposeViewController ();
         mailController.SetToRecipients (new string[] { "*****@*****.**" });
         mailController.Finished += (finishSender, finishE) => {
             finishE.Controller.DismissViewController (true, null); };
         this.PresentViewController (mailController, true, null);
     }
 }
Ejemplo n.º 44
0
 void OnEmailSelected(string emailAddress)
 {
     if (MFMailComposeViewController.CanSendMail) {
         var composer = new MFMailComposeViewController ();
         composer.SetToRecipients (new string[] { emailAddress });
         composer.Finished += (sender, e) => DismissViewController (true, null);
         PresentViewController (composer, true, null);
     } else {
         new UIAlertView ("Oops", "Email is not available", null, "Ok").Show ();
     }
 }
		MFMailComposeViewController configuredMailComposeViewController ()
		{
			var mailComposerVC = new MFMailComposeViewController ();
			mailComposerVC.MailComposeDelegate = this;

			mailComposerVC.SetToRecipients(new [] { AppKeys.ContactEmail });
			mailComposerVC.SetSubject(AppKeys.Contact.IntegrationSubject);
			mailComposerVC.SetMessageBody(AppKeys.Contact.IntegrationBody, false);

			return mailComposerVC;
		}
Ejemplo n.º 46
0
 private void ContactUs()
 {
     if (MFMailComposeViewController.CanSendMail)
     {
         _mailViewController = new MFMailComposeViewController();
         _mailViewController.SetToRecipients(new[] { "*****@*****.**" });
         _mailViewController.Finished += (sender, e) => e.Controller.DismissViewController(true, null);
         _mailViewController.SetSubject("Feedback");
         PresentViewController(_mailViewController, true, null);
     }
 }
		public void Compose(string to, string subject, string body)
		{
			var mail = new MFMailComposeViewController();
			mail.SetToRecipients(new [] {to});
			mail.SetSubject(subject);
			mail.SetMessageBody(body, false);

			mail.Finished += (sender, args) => args.Controller.DismissViewController(true, null);

			UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mail, true, null);
		}
Ejemplo n.º 48
0
 public void ShowDraft(string subject, string body, bool html, string[] to, string[] cc, string[] bcc)
 {
     var mailer = new MFMailComposeViewController();
     mailer.SetMessageBody(body ?? string.Empty, html);
     mailer.SetSubject(subject ?? string.Empty);
     mailer.SetCcRecipients(cc);
     mailer.SetToRecipients(to);
     mailer.Finished += (s, e) =>
     {
         ((MFMailComposeViewController)s).DismissViewController(true, () => { });
     };
 }
Ejemplo n.º 49
0
		public static MFMailComposeViewController Email (string[] recipients, string subject)
		{
			var mailController = new MFMailComposeViewController ();

			mailController.SetToRecipients (recipients);
			mailController.SetSubject (subject);

			mailController.Finished += ( object s, MFComposeResultEventArgs e) => {
				e.Controller.DismissViewController (true, null);
			};

			return mailController;
		}
Ejemplo n.º 50
0
		private void CreateMail(string html)
		{
			if (MFMailComposeViewController.CanSendMail) {
	            _mail = new MFMailComposeViewController ();
				_mail.NavigationBar.BarStyle = UIBarStyle.Black;
				_mail.Title = Utils.Translate("sendmail");
				if(jakt != null)
					_mail.SetSubject(string.Format(Utils.Translate("mailsubject"), jakt.Sted, jakt.DatoFra.ToLocalDateAndYearString()));
	            else 
					_mail.SetSubject(Utils.Translate("mailsubject_generic"));
				
				_mail.SetMessageBody (html, true);
	            _mail.Finished += HandleMailFinished;
				
				
				//Get e-mails:
				var selectedJegerIds = new List<int>();
				var jegerIds = JaktLoggApp.instance.JegerList.Select(j => j.ID).ToList<int>();
				if(jakt != null)
					jegerIds = jakt.JegerIds;
				
				var jegerScreen = new JegerPickerScreen(jegerIds, screen => {
					selectedJegerIds = screen.jegerIds;
					//get email pr. jegerid
					if(selectedJegerIds.Count > 0){
						List<string> emails = new List<string>();
						foreach(var jegerId in selectedJegerIds){
							var jeger = JaktLoggApp.instance.JegerList.Where(j => j.ID == jegerId).FirstOrDefault();
							if(jeger.Email != "")
								emails.Add(jeger.Email);
							else
								MessageBox.Show(string.Format(Utils.Translate("report.mailmissing"), jeger.Fornavn), "");
						}
						if(emails.Count > 0)
							_mail.SetToRecipients(emails.ToArray());
						
					}
					this.PresentModalViewController (_mail, true);
				});
				jegerScreen.Title = Utils.Translate("report.jegereheader");
				jegerScreen.Footer = Utils.Translate("report.jegerefooter");
				jegerScreen.ModalTransitionStyle = UIModalTransitionStyle.CoverVertical;
				
				this.NavigationController.PushViewController(jegerScreen, true);
	            
	        } 
			else {
	        	MessageBox.Show(Utils.Translate("sorry"), Utils.Translate("error_mailnotsupported"));
	        }

		}
Ejemplo n.º 51
0
        public void ShowDraft(string subject, string body, bool html, string[] to, string[] cc, string[] bcc, IEnumerable<string> attachments)
        {
            var mailer = new MFMailComposeViewController();
            mailer.SetMessageBody(body ?? string.Empty, html);
            mailer.SetSubject(subject ?? string.Empty);
            mailer.SetCcRecipients(cc);
            mailer.SetToRecipients(to);
            mailer.Finished += (s, e) =>
            {
                ((MFMailComposeViewController)s).DismissViewController(true, () => { });
            };

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);
        }
		public bool Email (string emailAddress)
		{
			if (MFMailComposeViewController.CanSendMail) {
				var composer = new MFMailComposeViewController ();
				composer.SetToRecipients (new string[] { emailAddress });
				composer.SetSubject ("Hello from EmployeeDirectory!");

				composer.Finished += (sender, e) => RootViewController.DismissViewController (true, null);
				RootViewController.PresentViewController (composer, true, null);
				return true;
			} else {
				return false;
			}
		}
Ejemplo n.º 53
0
        public void ComposeEmail(string to, string cc, string subject, string body, bool isHtml)
        {
            if (!MFMailComposeViewController.CanSendMail)
                return;

            _mail = new MFMailComposeViewController();
            _mail.SetMessageBody(body ?? string.Empty, isHtml);
            _mail.SetSubject(subject ?? string.Empty);
            _mail.SetCcRecipients(new[] {cc ?? string.Empty});
            _mail.SetToRecipients(new[] {to ?? string.Empty});
            _mail.Finished += HandleMailFinished;

            _presenter.PresentModalViewController(_mail, true);
        }
Ejemplo n.º 54
0
        public void SendEmail(string toAddress, string subject, string body)
        {
            MFMailComposeViewController _mailController = new MFMailComposeViewController();
            _mailController.SetToRecipients(new string[] { toAddress });
            _mailController.SetSubject(subject);
            _mailController.SetMessageBody(body, false);

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

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(_mailController, true, null);    
        }
Ejemplo n.º 55
0
 public void ComposeMail(string[] recipients, string subject, string messagebody = null, Action<bool> completed = null)
 {
     var controller = new MFMailComposeViewController();
     controller.SetToRecipients(recipients);
     controller.SetSubject(subject);
     if (!string.IsNullOrEmpty(messagebody))
         controller.SetMessageBody(messagebody, false);
     controller.Finished += (object sender, MFComposeResultEventArgs e) => {
         if (completed != null)
             completed(e.Result == MFMailComposeResult.Sent);
         e.Controller.DismissViewController(true, null);
     };
     
     UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(controller, true, null);
 }
Ejemplo n.º 56
0
		public void ComposeEmail(string to, string cc, string subject, string body, bool isHtml, byte[] attachment)
		{
			
			if (!MFMailComposeViewController.CanSendMail)
				return;
			
			_mail = new MFMailComposeViewController ();
			_mail.SetMessageBody (body ?? string.Empty, isHtml);
			_mail.SetSubject(subject ?? string.Empty);
			_mail.SetCcRecipients(new [] {cc ?? string.Empty});
			_mail.SetToRecipients(new [] {to ?? string.Empty});
			_mail.AddAttachmentData(NSData.FromArray(attachment), "image/jpeg", "screenshot.jpg");
			_mail.Finished += HandleMailFinished;
			
			_presenter.PresentModalViewController(_mail, true);
		}
Ejemplo n.º 57
0
 public Bullying()
     : base(UITableViewStyle.Grouped, null)
 {
     Title = NSBundle.MainBundle.LocalizedString ("Bullying", "Bullying");
     TabBarItem.Image = UIImage.FromBundle("bullying");
     //			var HelpButton = new UIButton(UIButtonType.RoundedRect);
     //			HelpButton.SetTitle("Help Me!", UIControlState.Normal);
     Root = new RootElement ("Student Guide") {
         new Section("Bullying"){
             new StyledStringElement ("Help me!", () => {
                 //AppDelegate.getControl.calling(); //Phones a number all like 'SAVE ME PLS'
             }){ TextColor=UIColor.Red,},
             new RootElement("Speak Up!") {
                 new Section("Speak up form") {
                     (FullName = new EntryElement("Full Name","Full Name","")),
                     (Incident = new EntryElement("Incedent","Incedent","",false)),
                     (Location = new EntryElement("Location of Incident","Location of Incident","")),
                     (ThoseInvolved = new EntryElement("Persons Involved","Persons Involved","")),
                 },
                 new Section() {
                     new StringElement("Submit", delegate {
                         UIAlertView popup = new UIAlertView("Alert","Do you wish to send an Email, a Text or cancel the form?",null,"Cancel","Text","Email");
                         popup.Show();
                         popup.Dismissed += delegate(object sender, UIButtonEventArgs e) {
                             if (e.ButtonIndex==1) {
                                 MFMessageComposeViewController msg = new MFMessageComposeViewController();
                                 msg.Recipients= new string[] {"07624808747"};
                                 msg.Body="Hello, I am being bullied by " + ThoseInvolved.Value + " they were " + Incident.Value + " this all happened " + Location.Value + "" + Environment.NewLine + "" + FullName.Value;
                                 this.NavigationController.PresentViewController(msg,true,null);
                             } else if (e.ButtonIndex==2) {
                                 MFMailComposeViewController email = new MFMailComposeViewController();
                                 email.SetSubject("Help me i'm being bullied");
                                 email.SetToRecipients(new string[] {"*****@*****.**"});
                                 email.SetMessageBody("Hello, I am being bullied by " + ThoseInvolved.Value + " they were " + Incident.Value + " this all happened " + Location.Value + "" + Environment.NewLine + "" + FullName.Value,false);
                                 this.NavigationController.PresentViewController(email,true,null);
                             }
                         };
                     }),
                 },
             },
             new RootElement("Bullying Information") {
                 from x in bullyingInfo
                     select (Section)Generate (x)
             },
         }
     };
 }
Ejemplo n.º 58
0
		public override async Task ExecuteAsync ()
		{
			await base.ExecuteAsync ();

			if (string.IsNullOrWhiteSpace (Address))
				return;

			var fromVC = UIApplication.SharedApplication.Windows [0].RootViewController;

			var c = new MFMailComposeViewController ();
			c.Finished += (sender, e) => c.DismissViewController (true, null);
			c.SetToRecipients (new [] { Address });
			c.SetSubject (Subject);
			c.SetMessageBody (BodyHtml, true);

			await fromVC.PresentViewControllerAsync (c, true);
		}
Ejemplo n.º 59
0
        // ReSharper disable once UnusedMember.Local
        // ReSharper disable once UnusedParameter.Local
partial         void SendMail(NSObject sender)
        {
            var mailController = new MFMailComposeViewController();

            mailController.SetToRecipients(new[]
            {
                Constants.FeedbackMail
            });
            mailController.SetSubject(_trans.GetString("FeedbackController_MailTitle"));

            mailController.Finished += (s, args) =>
            {
                Logger.Logg(args.Result.ToString());
                args.Controller.DismissViewController(true, null);
            };

            PresentViewController(mailController, true, null);
        }
Ejemplo n.º 60
0
        public void SendEmail(IEmailMessage email)
        {
            if (email == null)
                throw new ArgumentNullException("email");

            if (CanSendEmail)
            {
                _mailController = new MFMailComposeViewController();
                _mailController.SetSubject(email.Subject);
                _mailController.SetMessageBody(email.Message, ((EmailMessage) email).IsHtml);
                _mailController.SetToRecipients(email.Recipients.ToArray());

                if (email.RecipientsCc.Count > 0)
                    _mailController.SetCcRecipients(email.RecipientsCc.ToArray());

                if (email.RecipientsBcc.Count > 0)
                    _mailController.SetBccRecipients(email.RecipientsBcc.ToArray());

                foreach (var attachment in email.Attachments.Cast<EmailAttachment>())
                {
                    _mailController.AddAttachmentData(NSData.FromStream(attachment.Content),
                        attachment.ContentType, attachment.FileName);
                }

                EventHandler<MFComposeResultEventArgs> handler = null;
                handler = (sender, e) =>
                {
                    _mailController.Finished -= handler;

                    var uiViewController = sender as UIViewController;
                    if (uiViewController == null)
                    {
                        throw new ArgumentException("sender");
                    }

                    uiViewController.DismissViewController(true, () => { });
                };

                _mailController.Finished += handler;

                _mailController.PresentUsingRootViewController();
            }
        }