flutter_email_sender 10.0.0
flutter_email_sender: ^10.0.0 copied to clipboard
Allows send emails from flutter using native platform functionality.
flutter_email_sender #
Allows send emails from flutter using native platform functionality.
In android it opens default mail app via intent.
In iOS MFMailComposeViewController is used to compose an email.
In macOS NSSharingService with .composeEmail is used to compose an email.
The plugin exposes platform capabilities so apps can adapt their UI before sending.
The public API throws typed Dart exceptions rather than exposing raw PlatformExceptions for expected failures.
Platform Support #
| Platform | cc |
bcc |
HTML body | Attachments |
|---|---|---|---|---|
| Android | Yes | Yes | Yes | Yes |
| iOS | Yes | Yes | Yes | Yes |
| macOS | No | No | No | Yes |
| Web | Yes | Yes | No | No |
Web support uses mailto: and depends on browser and configured mail client behavior.
Example #
final capabilities = await FlutterEmailSender.getCapabilities();
if (!capabilities.canSend) {
// No configured mail account, simulator, or no available mail client.
}
final Email email = Email(
body: 'Email body',
subject: 'Email subject',
recipients: ['example@example.com'],
cc: capabilities.supportsCc ? ['cc@example.com'] : const [],
bcc: capabilities.supportsBcc ? ['bcc@example.com'] : const [],
attachmentPaths: capabilities.supportsAttachments
? ['/path/to/attachment.zip']
: null,
isHTML: capabilities.supportsHtmlBody,
);
await FlutterEmailSender.send(email);
try {
await FlutterEmailSender.send(email);
} on FlutterEmailSenderNotAvailableException {
// Email composer is unavailable on this device right now.
} on FlutterEmailSenderUnsupportedFeatureException catch (error) {
// Requested features are unsupported on the current platform.
debugPrint('Unsupported: ${error.unsupportedFeatures}');
}
Errors #
FlutterEmailSenderNotAvailableException: no email composer is currently available.FlutterEmailSenderUnsupportedFeatureException: requested fields are unsupported on the current platform.FlutterEmailSenderPlatformException: unexpected platform/plugin error.
Migrating From 9.x To 10.0.0 #
sendandgetCapabilitiesnow throw typed Dart exceptions for expected failures.- Apps that previously caught
PlatformException(code: 'not_available')should catchFlutterEmailSenderNotAvailableExceptioninstead. - Apps that previously caught
PlatformException(code: 'unsupported')should catchFlutterEmailSenderUnsupportedFeatureExceptioninstead. - Use
getCapabilities()andEmailCapabilities.canSendto adapt UI before callingsend.
Local Development #
When consuming this plugin from a local path before all federated packages are published, point to packages/flutter_email_sender and override the internal federated packages in pubspec_overrides.yaml.
Android Setup #
With Android 11, package visibility is introduced that alters the ability to query installed applications and packages on a user's device. To enable your application to get visibility into the packages you will need to add a list of queries into your AndroidManifest.xml.
<manifest package="com.mycompany.myapp">
<queries>
<intent>
<action android:name="android.intent.action.SENDTO" />
<data android:scheme="mailto" />
</intent>
</queries>
</manifest>