Example #1
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);
        }
Example #2
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);
        }
        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");
				}
            };
        }
        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 SendEmail(string attachment)
        {
            MFMailComposeViewController mailController;

            if (MFMailComposeViewController.CanSendMail)
            {
                mailController = new MFMailComposeViewController();
                //mailController.SetToRecipients(new string[] { "*****@*****.**" });
                mailController.SetSubject("Mileage Report");
                mailController.SetMessageBody("Mileage report exported from MileageApp", false);

                var fileHelper = new FileHelper();
                var stream     = fileHelper.ReadFileContents(attachment);
                mailController.AddAttachmentData(NSData.FromStream(stream), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "expense report.xlsx");

                mailController.Finished += (object sender, MFComposeResultEventArgs e) =>
                {
                    // can set pass in an action to call when done
                    //if (completed != null)
                    //   completed(e.Result == MFMailComposeResult.Sent);
                    e.Controller.DismissViewController(true, null);

                    // is this the right place to close this? not sure if it copies the stream over before this
                    stream.Close();
                };

                // http://stackoverflow.com/questions/24136464/access-viewcontroller-in-dependencyservice-to-present-mfmailcomposeviewcontrolle
                //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(mailController, true, null);
                UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailController, true, null);
            }
        }
        public void Share(string message, string title = "", ShareType shareType = ShareType.Sms)
        {
/*          if (MFMessageComposeViewController.CanSendText)
 *          {
 *              var smsCtrl = new MFMessageComposeViewController();
 *              smsCtrl.Body = message;
 *              smsCtrl.Subject = title;
 *              smsCtrl.Finished += (sender, args) =>
 *              {
 *                  Debug.WriteLine("finished");
 *              };
 *
 *              _modalHost.PresentModalViewController(smsCtrl, true);
 *          }*/

            if (MFMailComposeViewController.CanSendMail)
            {
                var mail = new MFMailComposeViewController();
                mail.SetSubject(title);
                // mail.SetToRecipients(new[] { "*****@*****.**" });
                mail.SetMessageBody(message, false);

                mail.Finished += (sender, args) =>
                {
                    Debug.WriteLine("Finished");
                    args.Controller.DismissViewController(true, null);
                };

                _modalHost.PresentModalViewController(mail, true);
            }
        }
		/// <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);
		}
Example #8
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");
                }
            };
        }
Example #9
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);
        }
Example #10
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);
        }
        /// <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);
        }
Example #12
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;
 }
Example #13
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
            }
Example #14
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.");
            }
        }
Example #15
0
        public static void OpenSender(string path, Action success, Action <string> error)
        {
#if __IOS__
            string[] split = path.Split('/');
            string   name  = split[split.Length - 1];

            var stream = new MemoryStream(FileUtils.PathToByteData(path));

            NSData data = NSData.FromStream(stream);

            try
            {
                MFMailComposeViewController controller = new MFMailComposeViewController();

                controller.SetSubject("Style: " + name);
                controller.SetMessageBody("Date: " + DateTime.Now.ToString("F"), false);
                controller.AddAttachmentData(data, "application/zip", name);

                controller.Finished += (object sender, MFComposeResultEventArgs e) =>
                {
                    string message = "";

                    if (e.Result == MFMailComposeResult.Sent)
                    {
                        message = "Mail sent";
                        success();
                    }
                    else if (e.Result == MFMailComposeResult.Failed)
                    {
                        message = "Failed :" + e.Error;
                    }
                    else if (e.Result == MFMailComposeResult.Cancelled)
                    {
                        message = "Cancelled";
                    }
                    else if (e.Result == MFMailComposeResult.Saved)
                    {
                        message = "Saved";
                        success();
                    }

                    Toast.Show(message, new BaseView());
                    controller.DismissViewController(true, null);
                };

                Controller.PresentViewController(controller, true, null);
            }
            catch
            {
                //error("You don't seem to have any mail clients set up");
            }
#elif __ANDROID__
            Intent intent = new Intent(Intent.ActionSend);
            intent.SetType("application/zip");

            intent.PutExtra(Intent.ExtraStream, Android.Net.Uri.Parse(path));

            Context.StartActivity(Intent.CreateChooser(intent, "Share zip"));
#endif
        }
Example #16
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);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            tv.BecomeFirstResponder();

            toolbar.Items[0].Clicked += (o, s) =>
            {
                string text    = tv.Text;
                NSData pdfData = CreatePDF(text, 500f, 700f);

                if (MFMailComposeViewController.CanSendMail)
                {
                    _mail = new MFMailComposeViewController();
                    _mail.SetMessageBody(tv.Text, false);
                    _mail.AddAttachmentData(pdfData, "text/x-pdf", "test.pdf");
                    _mail.Finished += HandleMailFinished;
                    this.PresentModalViewController(_mail, true);
                }
                else
                {
                    UIAlertView alert = new UIAlertView("App", "Could not send mail.", null, "OK", null);
                    alert.Show();
                }
            };

            toolbar.Items[1].Clicked += (o, s) =>
            {
                _pdf = new PDFViewController(tv.Text);
                this.PresentModalViewController(_pdf, true);
            };
        }
        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);
        }
Example #19
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;
        }
        // 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);
            }
        }
        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);
            }
        }
        private void SendByMail()
        {
            UIGraphics.BeginImageContext(chart.Frame.Size);
            var ctx = UIGraphics.GetCurrentContext();

            if (ctx != null)
            {
                chart.Layer.RenderInContext(ctx);
                UIImage img = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

                if (MFMailComposeViewController.CanSendMail)
                {
                    _mail = new MFMailComposeViewController();

                    _mail.AddAttachmentData(img.AsPNG(), "image/png", "image.png");
                    _mail.SetSubject("Chart from TeeChart Builder for iPhone");

                    _mail.SetMessageBody("This is the Chart sent through TeeChart app.", false);
                    _mail.Finished += HandleMailFinished;

                    this.PresentModalViewController(_mail, true);
                }
                else
                {
                    // handle not being able to send mail
                }
            }
        }
Example #23
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);
            }
        }
Example #24
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);
            }
        }
Example #25
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);
    }
Example #26
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);
        }
        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);
            }
        }
Example #28
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);
        }
Example #29
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);
        }
Example #30
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);
        }
Example #31
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);
        }
        private void Email(string exportType)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                return;
            }

            var    title          = exampleInfo.Title + "." + exportType;
            NSData nsData         = null;
            string attachmentType = "text/plain";
            var    rect           = new CGRect(0, 0, 800, 600);

            switch (exportType)
            {
            case "png":
                nsData         = View.ToPng(rect);
                attachmentType = "image/png";
                break;

            case "pdf":
                nsData         = View.ToPdf(rect);
                attachmentType = "text/x-pdf";
                break;
            }

            var mail = new MFMailComposeViewController();

            mail.SetSubject("OxyPlot - " + title);
            mail.SetMessageBody("Please find attached " + title, false);
            mail.Finished += HandleMailFinished;
            mail.AddAttachmentData(nsData, attachmentType, title);

            this.PresentViewController(mail, true, null);
        }
Example #33
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);
            }
        }
Example #34
0
        public void SendMail(MemoryStream stream)
        {
            SaveExcel(stream);

            string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string filePath = Path.Combine(path, "reports.xlsx");

            NSData data = NSData.FromFile (filePath);

            if (MFMailComposeViewController.CanSendMail)
            {
                var mail = new MFMailComposeViewController ();
                mail.SetSubject ("Exports");
                mail.SetMessageBody ("Hi, Please find the report here.", false);
                mail.AddAttachmentData (data, "application/vnd.ms-excel", "reports.xlsx");

                var window= UIApplication.SharedApplication.KeyWindow;
                var vc = window.RootViewController;
                vc.PresentViewController (mail, false, null);

                mail.Finished += ( object s, MFComposeResultEventArgs args) => {

                        args.Controller.DismissViewController (true, null);

                };
            }
        }
Example #35
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);
        }
Example #36
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);
    }
        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");
				}
            };
        }
Example #38
0
        /// <summary>
        /// Use this method to compose mail
        /// </summary>
        /// <param name="fileName">string type of parameter fileName</param>
        /// <param name="recipients">string type of parameter recipients</param>
        /// <param name="subject">string type of parameter subject</param>
        /// <param name="messagebody">string type of parameter message body</param>
        /// <param name="stream">MemoryStream type parameter stream</param>
        public void ComposeMail(string fileName, string[] recipients, string subject, string messagebody, MemoryStream stream)
        {
            if (MFMailComposeViewController.CanSendMail)
            {
                var mailer = new MFMailComposeViewController();
                mailer.SetMessageBody(messagebody ?? string.Empty, false);
                mailer.SetSubject(subject ?? subject);
                mailer.Finished += (s, e) => ((MFMailComposeViewController)s).DismissViewController(true, () => { });

                string exception = string.Empty;
                string path      = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                string filePath  = Path.Combine(path, fileName);
                try
                {
                    FileStream fileStream = File.Open(filePath, FileMode.Create);
                    stream.Position = 0;
                    stream.CopyTo(fileStream);
                    fileStream.Flush();
                    fileStream.Close();
                }
                catch (Exception e)
                {
                    exception = e.ToString();
                }

                mailer.AddAttachmentData(NSData.FromFile(filePath), this.GetMimeType(fileName), Path.GetFileName(fileName));
                UIViewController vc = UIApplication.SharedApplication.KeyWindow.RootViewController;
                while (vc.PresentedViewController != null)
                {
                    vc = vc.PresentedViewController;
                }

                vc.PresentViewController(mailer, true, null);
            }
        }
 public override void ViewDidLoad ()
 {
     base.ViewDidLoad ();
     
     tv.BecomeFirstResponder ();
     
     toolbar.Items[0].Clicked += (o, s) =>
     {
         string text = tv.Text;
         NSData pdfData = CreatePDF (text, 500f, 700f);
         
         if (MFMailComposeViewController.CanSendMail) {
             _mail = new MFMailComposeViewController ();
             _mail.SetMessageBody (tv.Text, false);
             _mail.AddAttachmentData (pdfData, "text/x-pdf", "test.pdf");
             _mail.Finished += HandleMailFinished;
             this.PresentModalViewController (_mail, true);
         } else {
             UIAlertView alert = new UIAlertView ("App", "Could not send mail.", null, "OK", null);
             alert.Show ();
         }
     };
     
     toolbar.Items[1].Clicked += (o, s) =>
     {
         _pdf = new PDFViewController (tv.Text);
         this.PresentModalViewController (_pdf, true);
     };
 }
Example #40
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();
            }
        }
Example #41
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);
        }
		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);
		}
		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;
		}
 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, () => { });
     };
 }
Example #45
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"));
	        }

		}
        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);
        }
Example #47
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);
        }
 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);
 }
        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);    
        }
		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);
		}
Example #51
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)
             },
         }
     };
 }
Example #52
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);
		}
Example #53
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();
            }
        }
Example #54
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            this.btnSend.TouchUpInside += (o, e) =>
            {
                if (MFMailComposeViewController.CanSendMail) {
                    _mail = new MFMailComposeViewController ();
                    _mail.SetMessageBody ("This is the body of the email",
                                          false);
                    _mail.Finished += HandleMailFinished;
                    this.PresentModalViewController (_mail, true);
                } else {
                    UIAlertView alert = new UIAlertView("email test",
                                                        "Email not available on this device", null, "Okay");
                    alert.Show();
                }
            };
        }
Example #55
0
 public void SendMail()
 {
     if (MFMailComposeViewController.CanSendMail)
     {
         mail = new MFMailComposeViewController();
         mail.SetSubject(Subject);
         mail.SetMessageBody(Body, false);
         mail.Finished += (sender, e) =>
         {
             var finished = OnFinished;
             if (finished != null)
                 finished(this, EventArgs.Empty);
             mail.Dispose();
             mail = null;
             controller.NavigationController.DismissModalViewControllerAnimated(true);
         };
         controller.NavigationController.PresentModalViewController(mail, true);
     }
 }
Example #56
0
        void OnNext(object sender, EventArgs e)
        {
            _mailController = new MFMailComposeViewController ();
            _mailController.Finished += OnFinished;

            LucidTableSource src = this.TableView.Source as LucidTableSource;

            if (TableView.IndexPathsForSelectedRows != null) {
                List<LucidContent> selected = new List<LucidContent> ();
                foreach (var i in TableView.IndexPathsForSelectedRows) {

                    selected.Add (src.TableItems [i.Row]);
                }
                _mailController.SetMessageBody(HtmlBuilder.ToHtml(selected),true);
            }

            this.PresentViewController(_mailController,true,null);
             var x = this._mailController.ChildViewControllers;
        }
Example #57
0
		private void CreateMail(string html)
		{
			if (MFMailComposeViewController.CanSendMail) {
	            _mail = new MFMailComposeViewController ();
				_mail.NavigationBar.BarStyle = UIBarStyle.Black;
				_mail.Title = "Send e-post";
				_mail.SetSubject("Jaktrapport for " + jakt.Sted + " " + jakt.DatoFra.ToNorwegianDateAndYearString());
	            _mail.SetMessageBody (html, true);
	            _mail.Finished += HandleMailFinished;
				
				
				//Get e-mails:
				var selectedJegerIds = new List<int>();
				var jegerScreen = new JegerPickerScreen(jakt.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("Kan ikke legge til e-post for " + jeger.Fornavn, "E-post adresse mangler i jegeroppsettet.");
						}
						if(emails.Count > 0)
							_mail.SetToRecipients(emails.ToArray());
						
					}
					this.PresentModalViewController (_mail, true);
				});
				jegerScreen.Title = "Velg mottakere";
				jegerScreen.Footer = "Jegerne du velger må ha registrert e-post";
				this.NavigationController.PushViewController(jegerScreen, true);

	            
	        } 
			else {
	        	MessageBox.Show("Beklager", "Denne enheten kan desverre ikke sende e-post");
	        }

		}
Example #58
0
        public void Email(string message, string subject, string[] recivers)
        {
            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) =>
            {
                Console.WriteLine(args.Result.ToString());
                args.Controller.DismissViewController(true, null);
            };

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailController, true, null);
        }
Example #59
0
        private void OnMailButtonClicked(object sender, EventArgs args)
        {
            if (!MFMailComposeViewController.CanSendMail)
            {
                Console.WriteLine("Can't send mail.");
                return;
            }

            _mailController = new MFMailComposeViewController();
            _mailController.SetToRecipients(new string[]{ _mail });
            _mailController.SetSubject("TouchInstinct Support");
            _mailController.SetMessageBody("Enter you message.", false);

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

            PresentViewController(_mailController, true, null);
        }
Example #60
0
        public virtual Task ComposeEmail(IEmailMessage emailMessage)
        {
            if (!CanComposeEmail)
            {
                throw new FeatureNotAvailableException();
            }

            var mailer = new MFMailComposeViewController();

            mailer.SetToRecipients(emailMessage.To.ToArray());
            mailer.SetCcRecipients(emailMessage.Cc.ToArray());
            mailer.SetBccRecipients(emailMessage.Bcc.ToArray());

            mailer.SetSubject(emailMessage.Subject);
            mailer.SetMessageBody(emailMessage.Body, emailMessage.IsHTML);

            mailer.Finished += (s, e) => ((MFMailComposeViewController) s).DismissViewController(true, () => { });

            UIApplication.SharedApplication.KeyWindow.RootViewController.PresentViewController(mailer, true, null);

            return Task.FromResult(true);
        }