Forum Xamarin.Forms

CrossMessaging is not working for me in iOS

Will.ItraxWill.Itrax CAMember ✭✭✭

I am using xam.plugins.messaging to send email from within a Xamarin Forms PCL app created in Visual Studio 2017.

The following works in android. It opens a local email client with a message pre-populated with what I would expect to see. When I press send, the email is sent and a few moments later I receive it a my.self.

var emailMessenger = CrossMessaging.Current.EmailMessenger;
if (emailMessenger.CanSendEmail)
    var email = new EmailMessageBuilder()
      .To("[email protected]")
      .Body("This is a test")

In iOS however, it does nothing. It does not open an email client and it does not send an email to my.self.
I would be grateful to anyone that can explain what I am missing here.

Best Answer


  • Luis_dmLuis_dm USMember ✭✭✭

    Xam.Plugins.Messaging, is installed on iOS?

  • Will.ItraxWill.Itrax CAMember ✭✭✭

    @LuisRodriguez92 Good question. Yes it is.

  • Luis_dmLuis_dm USMember ✭✭✭

    Are you testing in a simulator?

  • Will.ItraxWill.Itrax CAMember ✭✭✭

    @LuisRodriguez92 No, on an ipad.

  • Luis_dmLuis_dm USMember ✭✭✭

    It could be that you have not logged in to the Mail application on the iPad. Check this.

  • Will.ItraxWill.Itrax CAMember ✭✭✭

    @LuisRodriguez92 Another good suggestion. Gmail was running and I also started Outlook up. Then I tried again. I can step through the code and at the end it does nothing. Not even a warning or error.

    Oh wait. There is a Warning:

                Warning: Attempt to present 
        <MFMailComposeViewController: 0x181d1a00> on        
                       <Xamarin_Forms_Platform_iOS_PageRenderer: 0x19e9aa60> 
        whose view is not in the window hierarchy!

    In Android, this code opens up an email client and is ready to send a message. I would expect iOS to work the same. It looks like it is trying to open something but can't. Have you come across this?

  • Luis_dmLuis_dm USMember ✭✭✭
    edited October 2017

    I referred to this Mail application : image

  • RogerSchmidlinRogerSchmidlin CHUniversity ✭✭✭

    Did anyone get this to work on iOS sending mails going through gmail?

  • Will.ItraxWill.Itrax CAMember ✭✭✭
    edited November 2017

    @RogerSchmidlin Thanks for asking. Your question prompted me to post this follow-up. First I'll post the code and then my experience. Unfortunately, I do not recall what got me from "It does not open an email client" to "it works".
    This is the heart of it:

                    var emailMessenger = CrossMessaging.Current.EmailMessenger;
                    if (emailMessenger.CanSendEmail)
                        string subject = Someclass.Subject;
                        var email = new EmailMessageBuilder()
                                  //.Cc("[email protected]")
                                  //.Bcc(new[] { "[email protected]", "[email protected]" })
                      .WithAttachment(SomeClass.FilePath, "pdf")

    What this does is open up the native email app with the subject filled in and the attachment, well, attached. Then I get to fill in the To: portion (as required by our specs).

    This works on some of my iOS devices but not all. The one it does not work on is a bit older and not used for sending email anyway, so it may not be set up for sending mail (that's a good thing to check for ahead of time ;- ) What I mean by 'does not work' - is it opens the mail client but nothing gets sent.

    Edit: In my test on iOS just now, I stopped when I pressed send and got the whoosh sound indicating that the mail was sent. However, it did not arrive at the destination. So, it is not quite working yet. Sorry.

    Edit 2: So, I tried it on a different iPad and it worked. Since the code is the same, it must have something to do with the setup of the devices.

  • DeveshMishraDeveshMishra USMember ✭✭

    I am trying to use the same plugin for sending email & sms. But unfortunately i am not able to install (plugin version 5.2.0) it in Visual Studio 2015. Getting error...

    Could not install package 'Xamarin.Android.Support.Core.Utils 27.0.2'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v8.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

  • Will.ItraxWill.Itrax CAMember ✭✭✭

    Can you move to VS 2017? That's what I am using.

  • Will.ItraxWill.Itrax CAMember ✭✭✭

    @Sreeee Thanks for the comments and links. Very helpful.

Sign In or Register to comment.