0

I am working in Xamarin ios. I need to implement mail functionality. I implemented the code and getting "Sent" in result. But it is not received by recipients. I am using MFMailComposeViewController to implement the mail functionality.

following is the code:

      if (MFMailComposeViewController.CanSendMail)
        {
            mailController = new MFMailComposeViewController();
            mailController.SetToRecipients(new string[] { abcd@gmail.com });
            mailController.SetSubject("");
            mailController.SetMessageBody("", false);
            mailController.Finished += (object s, MFComposeResultEventArgs args) =>
            {
                                   args.Controller.DismissViewController(true, null);
            };

        }
anand
  • 1,399
  • 5
  • 23
  • 55
  • is this `abcd@gmail.com` valid mailID , if not chek your own mail – Anbu.Karthik Jan 09 '18 at 04:58
  • this is just for example, in my real code I am using my own email id – anand Jan 09 '18 at 04:59
  • see this one for help https://stackoverflow.com/questions/2481029/when-will-mfmailcomposeviewcontroller-cansendmail-return-no – Anbu.Karthik Jan 09 '18 at 05:01
  • I am getting true in "CanSendMail", and sending the mail successfully, but it is not received – anand Jan 09 '18 at 05:05
  • did the real phone configured with valid email account .check this code in real device . and don't forget to check the network connectivity of the phone – Vinodh Jan 09 '18 at 06:19
  • Yes I am testing it in real device configured with valid email id. – anand Jan 09 '18 at 06:39
  • You need to Present The controller on the view as Well. You have bind the finish event but havent dispayed the MFMailComposeViewController. – soan saini Jan 10 '18 at 00:02

1 Answers1

0
if (MFMailComposeViewController.CanSendMail)
    {
        mailController = new MFMailComposeViewController();
        mailController.SetToRecipients(new string[] { abcd@gmail.com });
        mailController.SetSubject("");
        mailController.SetMessageBody("", false);

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

    }

Mail Controller needs to be displayed on top of current controller. So Add the last line and try running the code.

It should open up a Email Window on top of your app. Where you can see all the details already filled up.

iOS doesnt allow you to send emails without opening up a email Client. So its on your user to either send the email or not.

soan saini
  • 230
  • 3
  • 9