katzer / cordova-plugin-email-composer

Edit and send email messages
Apache License 2.0
345 stars 336 forks source link

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

Open Florian-crg opened 2 years ago

Florian-crg commented 2 years ago

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.

synapdk commented 2 years ago

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

Florian-crg commented 2 years ago

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

PetePrattis commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

Florian-crg commented 2 years ago

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

You can reproduce the bug with the instruction I gave in https://github.com/katzer/cordova-plugin-email-composer/issues/363#issue-989728322.

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

jfoclpf commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

@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:sb@sw.com?subject=title&body=content"

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

UIApplication *application = [UIApplication sharedApplication];
    [application openURL:[NSURL URLWithString: encodedString] options:@{} completionHandler:nil];
afulkersonApollo commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

That is correct.

jfoclpf commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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

jfoclpf commented 2 years ago

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 commented 5 months ago

Testing this on iOS 17.3, I noted the following:

So: