Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cordova-plugin-email-composer does not work on iOS 13+ #363

Open
Florian-crg opened this issue Sep 7, 2021 · 26 comments
Open

cordova-plugin-email-composer does not work on iOS 13+ #363

Florian-crg opened this issue Sep 7, 2021 · 26 comments

Comments

@Florian-crg
Copy link

Florian-crg commented Sep 7, 2021

Impossible to make cordova-plugin-email-composer work on IOS 14.7.

I have GMAIL APP as a default email.

Apple Mail is deleted and I got Outlook APP which is not set as default.

Despite of having two mail Apps with on set by default it does not work.

@Florian-crg Florian-crg changed the title Cant send email IOS 14 cordova-plugin-email-composer does not work on IOS 14 Sep 7, 2021
@synapdk
Copy link

synapdk commented Oct 5, 2021

This is a showstopper for us. Has anyone found a workaround or alternative?

@Florian-crg
Copy link
Author

Yes you can use simple html https://css-tricks.com/snippets/html/mailto-links/

@PetePrattis
Copy link

To make ios able to communicate with other mailer apps you need to add in the info.plist the url scheme of these apps under LSApplicationQueriesSchemes, for example for iMail, gmail & outlook apps:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
<string>googlegmail</string>
<string>ms-outlook</string>
</array>

Now if you read the plugin's documentation there is a function that can easily check if a specified mailer app is installed and use that app. Use:
cordova.plugins.email.hasClient(app, callback)
where app is a string, for iMail, gmail, outlook is 'mailto', 'gmail', 'outlook' respectively.

And then use the specified app as a param in :

cordova.plugins.email.open({
    app: app,
    ...
})

I have to warn you that I read in other issues that Apple only allows the iMail app to pass attachments and attach files (also tested it and indeed only iMail can attach files). In other use cases the other mailer apps work properly.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 26, 2021

@PetePrattis would you be so kind to make a PR on that?

I don't have iOS so I don't have means to test it (I'm a collaborator of the project, not the initial creator), but I guess you can add these configurations in this repo's plugin.xml under <platform name="ios">, more precisely here.

You can use xml config-file or edit-config entry.

Something like

<config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes">
  <array>
    <string>mailto</string>
    <string>googlegmail</string>
    <string>ms-outlook</string>
  </array>
</config-file>

What do you think? Could you kindly test it?

Also consider that the directories plugins/ and platforms/ are normally volatile in cordova projects, thus you should not rely on files saves therein. All configurations should be done either in config.xml for sole projects or plugin.xml for plugins.

Thanks a lot in advance

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 26, 2021

@Florian-crg could you kindly also test it, that is, adding this under <platform name="ios"> on the plugin.xml file of this plugin?

<config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes">
  <array>
    <string>mailto</string>
    <string>googlegmail</string>
    <string>ms-outlook</string>
  </array>
</config-file>

Don't forget to rebuild the project in that case. Thanks a lot

jfoclpf added a commit that referenced this issue Nov 26, 2021
@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 26, 2021

I realized now that plugin.xml had already that entry but only with <string>mailto</string>. I already made a PR (#370) including <string>googlegmail</string> and <string>ms-outlook</string>.

Could you kindly test this PR?

cordova plugin rm cordova-plugin-email-composer
cordova plugin add github:katzer/cordova-plugin-email-composer#pull/370/head
cordova clean && cordova build ios

@PetePrattis @Florian-crg @synapdk @ocean999882

@jfoclpf jfoclpf changed the title cordova-plugin-email-composer does not work on IOS 14 cordova-plugin-email-composer does not work on iOS 13+ Nov 26, 2021
@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 29, 2021

@Florian-crg Florian can you test it PLEASE? This is open source, let's have a collaborative working spirit.

@Florian-crg
Copy link
Author

Florian-crg commented Nov 29, 2021

Sorry it was a company project, unfortunately I cannot reproduce it.

You can reproduce the bug with the instruction I gave in #363 (comment).

I am sorry not to be able to do more. Maybe @synapdk can help you.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Nov 29, 2021

@Florian-crg I am a collaborator of the project, not the initial creator, I cannot reproduce the problem because I have no Mac nor iOS. Do you know anyone with iOS 13+ that can reproduce it?

Just do it:

cordova plugin rm cordova-plugin-email-composer
cordova plugin add github:katzer/cordova-plugin-email-composer#pull/370/head
cordova clean && cordova build ios

@CyrixInstead
Copy link

@Florian-crg I am a collaborator of the project, not the initial creator, I cannot reproduce the problem because I have no Mac nor iOS. Do you know anyone with iOS 13+ that can reproduce it?

I have this problem too and unfortunately, this fix didn't help. I have tested with an iPhone 6 and iPhone 12 both on the latest version of iOS (15). The issue is with the mailto app so adding new apps presumably would only allow it to work with said new apps and does not resolve the actual issue. In my open command I added in app: 'mailto' in case the default/fallback did not work, but it didn't help.

The only thing I can really add to the conversation is that after the mail app should have opened and my own app is sitting there, opening the iPhone's task manager (double press the home button on the iPhone 6, swipe up from the bottom of the screen on the iPhone 12) brings up the thumbnail of my app and the mail app then opens whilst the task manager is open. If I then return to my app, the mailto app is visible.

So there's definitely something stopping the mail app showing in the foreground, but it is actually successfully opening the mail app. Obviously, having to open the task manager to get the mail app to show within your own app is a showstopper.

I should point out that my app is pretty old and I am working with XCode 10.1 and opening the email composer app from within an Ionic 1 app. I'm happy to try to help further if necessary.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Dec 1, 2021

@CyrixInstead
Do you know if that works (opening mailto) on previous versions of iOS? Or did you test it only with iOS 15?

Sorry anyway, but I have no iOS nor Mac, I think you have to go through the Apple Objective-C code here on this plugin

considering this

stringByAddingPercentEscapesUsingEncoding and openURL are deprecated.

#define URLEMail @"mailto:[email protected]?subject=title&body=content"

NSString * encodedString = [URLEMail stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];

UIApplication *application = [UIApplication sharedApplication];
    [application openURL:[NSURL URLWithString: encodedString] options:@{} completionHandler:nil];

@afulkersonApollo
Copy link

To make ios able to communicate with other mailer apps you need to add in the info.plist the url scheme of these apps under LSApplicationQueriesSchemes, for example for iMail, gmail & outlook apps:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
<string>googlegmail</string>
<string>ms-outlook</string>
</array>

Now if you read the plugin's documentation there is a function that can easily check if a specified mailer app is installed and use that app. Use: cordova.plugins.email.hasClient(app, callback) where app is a string, for iMail, gmail, outlook is 'mailto', 'gmail', 'outlook' respectively.

And then use the specified app as a param in :

cordova.plugins.email.open({
    app: app,
    ...
})

I have to warn you that I read in other issues that Apple only allows the iMail app to pass attachments and attach files (also tested it and indeed only iMail can attach files). In other use cases the other mailer apps work properly.

Why isn't this mentioned in the docs?

@jfoclpf
Copy link
Collaborator

jfoclpf commented Dec 8, 2021

@afulkersonApollo please read the thread, that's exactly what we were trying to avoid with the PR, but I found no one to test it.

@afulkersonApollo
Copy link

afulkersonApollo commented Dec 9, 2021

@afulkersonApollo please read the thread, that's exactly what we were trying to avoid with the PR, but I found no one to test it.

I had a coworker who is using Gmail on iOS 14 try this and it didn't work.

Additionally, using a mailto: link doesn't seem to work either. My coworker uninstalled the default iOS app and even though Gmail is set to default, it's asking him to reinstall the default mail client.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Dec 9, 2021

Do you mean this?

cordova plugin rm cordova-plugin-email-composer
cordova plugin add github:katzer/cordova-plugin-email-composer#pull/370/head
cordova clean && cordova build ios

@afulkersonApollo
Copy link

github:katzer/cordova-plugin-email-composer#pull/370/head

That is what I mean. The console returns:

[MFMailComposeViewController] Unable to initialize due to + 
[MFMailComposeViewController canSendMail] returns NO.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Dec 9, 2021

@afulkersonApollo do you confirm that after the cordova build ios (somewhere) inside platforms/ios the -Info.plist has:

<config-file target="*-Info.plist" parent="LSApplicationQueriesSchemes">
  <array>
    <string>mailto</string>
    <string>googlegmail</string>
    <string>ms-outlook</string>
  </array>
</config-file>

just be sure

@afulkersonApollo
Copy link

That is correct.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Dec 9, 2021

In that case unfortunately I can't do much, because I'm solely a maintainer of the this repo, I'm not the original creator nor I have mac or iphone, just android. You'll have to go through the code here in which case I would kindly request you to submit a PR if you find the solution for the problem.

@jayaprasanth-g
Copy link

To make ios able to communicate with other mailer apps you need to add in the info.plist the url scheme of these apps under LSApplicationQueriesSchemes, for example for iMail, gmail & outlook apps:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
<string>googlegmail</string>
<string>ms-outlook</string>
</array>

Now if you read the plugin's documentation there is a function that can easily check if a specified mailer app is installed and use that app. Use: cordova.plugins.email.hasClient(app, callback) where app is a string, for iMail, gmail, outlook is 'mailto', 'gmail', 'outlook' respectively.

And then use the specified app as a param in :

cordova.plugins.email.open({
    app: app,
    ...
})

I have to warn you that I read in other issues that Apple only allows the iMail app to pass attachments and attach files (also tested it and indeed only iMail can attach files). In other use cases the other mailer apps work properly.

May I know how come iOS email alone allowing to attch the email?. The outlook with email attachement is much needed for my project. Could you please give some suggessions?

@afulkersonApollo
Copy link

To make ios able to communicate with other mailer apps you need to add in the info.plist the url scheme of these apps under LSApplicationQueriesSchemes, for example for iMail, gmail & outlook apps:

<key>LSApplicationQueriesSchemes</key>
<array>
<string>mailto</string>
<string>googlegmail</string>
<string>ms-outlook</string>
</array>

Now if you read the plugin's documentation there is a function that can easily check if a specified mailer app is installed and use that app. Use: cordova.plugins.email.hasClient(app, callback) where app is a string, for iMail, gmail, outlook is 'mailto', 'gmail', 'outlook' respectively.
And then use the specified app as a param in :

cordova.plugins.email.open({
    app: app,
    ...
})

I have to warn you that I read in other issues that Apple only allows the iMail app to pass attachments and attach files (also tested it and indeed only iMail can attach files). In other use cases the other mailer apps work properly.

May I know how come iOS email alone allowing to attch the email?. The outlook with email attachement is much needed for my project. Could you please give some suggessions?

May I ask if you were having this problem and did the recommended solution solve it?

@jfoclpf
Copy link
Collaborator

jfoclpf commented Dec 16, 2021

@jayaprasanth-g your question is offtopic, but anyway,
attaching files in iOS may be a bit tricky and painful, please see the file plugin docs for apache cordova and also the docs for this plugin itself.

The easiest and fastest way to do it is via base64, try for example this

cordova.plugins.email.open({
    subject:     'Icon',
    attachments: ['base64:icon.png//iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABmJLR0QA/wD/AP+gvaeTAAABaUlEQVRIid2VPU7DQBCFPxzFDeEKHCDhDoQCShQilCtERAjIJVDEGaDi5zCIhoDABGjhAKYgBTHFzOIV2rXXSZcnjTbyzL63eZ5Zw7IjBnrADZAAXxoJcK25eF7yLvAOZCXxBuxVIY6AM4vgHjgCmsCqRgs4BsZW3Uj3lsKQfwP9kk0RcKC1RqQQXYt8M+Q0irYl0vEVxeSe9z01xg4XBpp7Bequgh655z5bigRqwIPm981Dm8h0wjkw85CsaLjwA1zob6dNL6re9BCEoKUciSuZarJRQFBkEcCa5lPzIKhvK8DY92exLfCh6/oCAmbvp0vgTtftBQR2dL11JU2bjpm/TR/516Y2YuTiypDxrypwqLkJnkEDmQVzVbR9RQ5sAVPk5e6WFY8skQHy132oISef6p7TkNNElkiGjP8JMkQNjQ1gSO75TMkrtX0HubjKPjgTAmzxoY50xBXwjExoCjwBl5rzvtDlwC8o13JbRpxVtAAAAABJRU5ErkJggg==']
});

You have several online tools to convert images to base64 and you can have your onw script to convert files on the fly to base64.

If you want to load files from the storage system you really have to read the file plugin docs for apache cordova.

@jayaprasanth-g
Copy link

Sorry this recommented solution not solve it. I can open the outlook app but the attachment is not working. they said it because of http://www.faqs.org/rfcs/rfc2368.html . I don't know how to resolve it.

@jayaprasanth-g
Copy link

@jfoclpf This is not work out. I can see the 'i' icon on iOS email but not outlook.

@jfoclpf
Copy link
Collaborator

jfoclpf commented Dec 16, 2021

Sorry this recommented solution not solve it. I can open the outlook app but the attachment is not working. they said it because of http://www.faqs.org/rfcs/rfc2368.html . I don't know how to resolve it.

I think they are referring to mailto and with mailto you cannot add attachments

https://stackoverflow.com/a/5233583

@dpa99c
Copy link

dpa99c commented Jan 31, 2024

Testing this on iOS 17.3, I noted the following:

  • If you set the default mail app to something other than Mail (Gmail/Outlook), then calling cordova.plugins.email.open({app: "mailto"}) still opens the Mail app
  • If you remove the Mail app:
    • Calling cordova.plugins.email.hasClient("mailto", (result) => console.log(result)) still results in true
    • Calling cordova.plugins.email.open({app: "mailto"}) is a noop
    • Click a mailto link in Safari results in the following:

So:

  • Using hasClient(), you are only able to tell if additional mail client apps are installed, not if the default one has been removed.
  • Removing the Mail app breaks the mailto scheme

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants