Search code examples
mailcore2

OAuth2 not working on Google Apps account with custom domain


I implemented OAuth support for Gmail and it's working great but if I login using a Google apps account (custom domain) I run into some issues. For example providerForEmail: doesn't work. Is there a workaround for this? I can set my hostname and port manually when creating a session but I pass MCOMailProvider around several methods in my app and I would need to change a lot of code plus the data model to store hostname/port separately.


Solution

  • To detect the email provider when the domain doesn't make it obvious, you need to do a DNS MX request. The result MX hostname can then be passed to -[MCOMailProvidersManager providerForMX:].

    The following issue on github documents how to perform a MX request: https://github.com/MailCore/mailcore2/issues/182