sidlatau / flutter_email_sender

Allows send emails from flutter using native platform functionality.
Apache License 2.0
156 stars 84 forks source link

Using Flutter_email_sender with IOS 13.5.1 #47

Open Colt94 opened 4 years ago

Colt94 commented 4 years ago

I am now getting this error when sending an email on my flutter app using my Iphone 6s (IOS 13.5.1). I suspect it has to do with the IOS update because it worked with previous IOS versions. Anyone else experiencing this issue? Using xcode 11.

2020-06-17 11:38:59.448606-0500 Runner[398:16848] [Common] [FBSSystemService][0x7292] Error handling open request for com.apple.mobilemail: <NSError: 0x2831d8960; domain: FBSOpenApplicationServiceErrorDomain; code: 1 (RequestDenied); reason: "The request was denied by service delegate (SBMainWorkspace) for reason: Security ("Un-trusted clients may not open applications in the background")."> { userInfo = { FBSOpenApplicationRequestID = 0x7292; } underlyingError = <NSError: 0x2831d8bd0; domain: FBSOpenApplicationErrorDomain; code: 3 (Security); reason: "Un-trusted clients may not open applications in the background.">; } 2020-06-17 11:38:59.448870-0500 Runner[398:17071] [General] #MailServices <MSAccounts: 0x282b4eb00> (0) : <connection: 0x280bebb40> failed to send message <dictionary: 0x281aaea60> NSError Domain=MailServices Code=2 2020-06-17 11:39:00.305431-0500

enhnarang commented 4 years ago

Hello Colt, thank you for posting this issue. I am facing the same problem, the android version works like a charm yet ios version email sender is not prompting to open the mailing apps.

ganger1 commented 4 years ago

Some Issue here

`[VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(not_available, No email clients found!, null)

0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)

1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)

#2 FlutterEmailSender.send (package:flutter_email_sender/flutter_email_sender.dart:10:21) #3 _SettingsPageState.sendEmail (package:hadyah/features/presentation/pages/setting/settings_page.dart:60:30) #4 _SettingsPageState.build.. (package:hadyah/features/presentation/pages/setting/settings_page.dart:150:41) #5 SettingsState.whenPartial (package:hadyah/features/presentation/blocs/settings/settings_state.g.dart:174:24) #6 _SettingsPageState.build. (package:hadyah/features/presentation/pages/setting/settings_page.dart:137:27) #7 _BlocListenerBaseState._subscribe. (p<…> [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(not_available, No email clients found!, null) #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33) #2 FlutterEmailSender.send (package:flutter_email_sender/flutter_email_sender.dart:10:21) #3 _SettingsPageState.sendEmail (package:hadyah/features/presentation/pages/setting/settings_page.dart:60:30) #4 _SettingsPageState.build.. (package:hadyah/features/presentation/pages/setting/settings_page.dart:150:41) #5 SettingsState.whenPartial (package:hadyah/features/presentation/blocs/settings/settings_state.g.dart:174:24) #6 _SettingsPageState.build. (package:hadyah/features/presentation/pages/setting/settings_page.dart:137:27) #7 _BlocListenerBaseState._subscribe. (p<…> [VERBOSE-2:ui_dart_state.cc(157)] Unhandled Exception: PlatformException(not_available, No email clients found!, null) #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7) #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33) #2 FlutterEmailSender.send (package:flutter_email_sender/flutter_email_sender.dart:10:21) #3 _SettingsPageState.sendEmail (package:hadyah/features/presentation/pages/setting/settings_page.dart:60:30) #4 _SettingsPageState.build.. (package:hadyah/features/presentation/pages/setting/settings_page.dart:145:43) #5 SettingsState.whenPartial (package:hadyah/features/presentation/blocs/settings/settings_state.g.dart:168:27) #6 _SettingsPageState.build. (package:hadyah/features/presentation/pages/setting/settings_page.dart:137:27)`
Motero69 commented 4 years ago

I have the same problem in IOS: the message I recived is : PlatformException(not_available, No email clients found!, null)

Any solutions?

FetFrumos commented 4 years ago

I have this issue on iOS. Any news?

sarn0ld commented 4 years ago

We have the same issue on iOS 14...

erperejildo commented 3 years ago

Same with iOS 13. Any solution yet?

josephmangmang commented 3 years ago

on ios not working. No email clients found!

jaffamd commented 2 years ago

I see how far back this thread goes, but for what it's worth, it's now January 2022 and this issue appears to be persistent. Android works fine after making the recommended change to AndroidManifest.xml, but iOS still gives the same error of "no email clients found". Anyone figure this out yet? Is it some kind of permissions issue? Something in the Info.plist?

levi956 commented 2 years ago

Seems there has been no fix. Is there project still actively maintained?

sidlatau commented 1 year ago

For the error No email clients found! - this plugin does not work in an iOS simulator, because the simulator does not have an email client, plugin works only on real devices. Maybe that is the issue?

IshchikGL commented 1 year ago

@sidlatau it's not working on iPhone 7+ (iOS 13.3.1). I'm getting PlatformException(not_available, No email clients found!, null, null) but there are a default client and Gmail installed. Maybe it's expecting some default app to be configured (not sure it could be done on iOS13)

clevertrevor commented 1 year ago

Reproducible on an iPhone 13 Pro with iOS 16.6, and I have repro steps! @sidlatau 100% reproducible when the iOS mail app is not logged in. Once logged in, I saw the new mail message modal pop up. The iPhone has Gmail installed/logged in, and the user's expectation would be for their preferred email client to open. Example: https://stackoverflow.com/a/55765362/2337925 If it's not possible, then IMHO it's a good idea to include a utility function to check whether the iOS Mail app can be opened.

Ahmadre commented 1 year ago

For the error No email clients found! - this plugin does not work in an iOS simulator, because the simulator does not have an email client, plugin works only on real devices. Maybe that is the issue?

It's also occuring on real devices.

lukehutch commented 3 months ago

This is occurring on a physical iPhone (one of my users' devices, iOS 17.x). The user reports that they uninstalled the Apple Mail app. They have the Gmail app installed, but the flutter_email_sender plugin does not seem to be able to send mail via Gmail.

This exception is thrown when MFMailComposeViewController.canSendMail() returns false

https://github.com/sidlatau/flutter_email_sender/blob/7520e976d2c33083e5b252c51a8030ffd3fdf409/ios/Classes/SwiftFlutterEmailSenderPlugin.swift#L34

which happens when there is no account set up to send mail on the device:

https://stackoverflow.com/questions/2481029/when-will-mfmailcomposeviewcontroller-cansendmail-return-no

Apparently also if Gmail is configured as default, the same error occurs, even if the Apple Mail app is installed:

https://forums.developer.apple.com/forums/thread/653146?answerId=645928022#645928022

It seems to me that the solution is to catch this PlatformException, and then on failure try using url_launcher instead. Something like this:

Future<void> sendEmail(Email email) async {
  try {
    await FlutterEmailSender.send(email);
  } catch (e, s) {
    final recipients = Uri.encodeComponent(email.recipients.join(','));
    final subject = Uri.encodeComponent(email.subject);
    final body = Uri.encodeComponent(email.body);
    final url = Uri.parse('mailto:$recipients?subject=$subject&body=$body');
    var success = false;
    try {
      if (await canLaunchUrl(url)) {
        success = await launchUrl(url);
      }
    } catch (e2) {
      logError(error: e2, message: 'Could not launch email url');
    }
    if (!success) {
      logError(error: e, message: 'Could not open email app');
      reportToCrashylitics(e, s);
      showSnackBar(
        'Could not open email app'
      );
    }
  }
}
GregUAs commented 3 weeks ago

@lukehutch

any solution for sending files in mail ? because url_launcher doesn't allow this feature...

lukehutch commented 3 weeks ago

@GregUAs there may be a special URL parameter for attachment path, but it will be platform-specific if it's even available at all. I don't know how to look up the URL spec for either Android or iOS.