I want to make a Flutter app and one of the requirements is to open the native email client on the Android or iPhone device. I do NOT wish to create a new email, just open the email app. I would like to be able to open the email client with platform generic code if possible, if not I would like to know what would be required on the iOS side. I am not looking for the Send Email Intent, as I know there is a plugin in Flutter for that. Being a Android Developer I believe I know how to call an Intent from Flutter for that Implicit Intent, if I have to go that way, but I don't have the familiarity with iOS.
Asked
Active
Viewed 2.5k times
7 Answers
41
The url_launcher plugin does that
mailto:<email address>?subject=<subject>&body=<body>
Create email to in the default email app
See also How do I open a web browser (URL) from my Flutter code?
Günter Zöchbauer
- 558,509
- 191
- 1,911
- 1,506
-
15I don't want to create a new email, I just want to open the default email app. – Peter Birdsall Jun 29 '18 at 17:35
-
Sorry, don't know about that – Günter Zöchbauer Jun 29 '18 at 17:37
-
Try `message:` instead of `mailto: ...` – Alejandro Iván Jul 04 '18 at 18:47
-
1You probably need to use `Uri.encodeFull('It is not ok')` or `Uri.encodeComponent('It isnot ok')` and pass the resulting value instead. – Günter Zöchbauer Dec 10 '18 at 06:57
-
@AlejandroIván is that just for iOS? – Volodymyr Bobyr Mar 10 '21 at 20:05
20
You need two plugins: android_intent and url_launcher
if (Platform.isAndroid) {
AndroidIntent intent = AndroidIntent(
action: 'android.intent.action.MAIN',
category: 'android.intent.category.APP_EMAIL',
);
intent.launch().catchError((e) {
;
});
} else if (Platform.isIOS) {
launch("message://").catchError((e){
;
});
}
BuffK
- 1,009
- 13
- 15
-
4On Android, this will open the email app inside your app. To open it in a new window add: `flags: [Flag.FLAG_ACTIVITY_NEW_TASK]` – Gabriel Aguirre May 16 '21 at 19:06
-
-
2
8
use url_launcher plugin url_launcher
Future<void> _launched;
Future<void> _openUrl(String url) async {
if (await canLaunch(url)) {
await launch(url);
} else {
throw 'Could not launch $url';
}
}
Then for Phone
setState(() {
_launched = _openUrl('tel:${+917600896744}');
});
for email
setState(() {
_launched = _openUrl('mailto:${sejpalbhargav67@gmail.com}'');
});
Update July 2021
Add Following Lines in Manifest File
<uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.DIAL" />
<data android:scheme="tel" />
</intent>
<intent>
<action android:name="android.intent.action.SEND" />
<data android:mimeType="*/*" />
</intent>
Bhargav Sejpal
- 939
- 12
- 19
0
You can use email_launcher
Example
Email email = Email(
to: ['one@gmail.com,two@gmail.com'],
cc: ['foo@gmail.com'],
bcc: ['bar@gmail.com'],
subject: 'subject',
body: 'body'
);
await EmailLauncher.launch(email);
heqingbao
- 258
- 2
- 5
0
this answer may be the solution How to open default email app inbox in flutter?
void openEmailApp(BuildContext context){
try{
AppAvailability.launchApp(Platform.isIOS ? "message://" : "com.google.android.gm").then((_) {
print("App Email launched!");
}).catchError((err) {
Scaffold.of(context).showSnackBar(SnackBar(
content: Text("App Email not found!")
));
print(err);
});
} catch(e) {
Scaffold.of(context).showSnackBar(SnackBar(content: Text("Email App not found!")));
}
}
Wisnu Wijokangko
- 714
- 1
- 9
- 12
-
AppAvailability is an outdated plugin, if you use this it will generate when you releasing the build . So please avoid using this plugin – scienticious Jun 07 '21 at 06:47
0
launch("mailto:<email address>?subject=<subject>&body=<body>");
use url_launcher package
saigopi.me
- 11,721
- 2
- 72
- 50
-3
This library solved it perfectly for me: https://pub.dev/packages/flutter_email_sender. The example is good and the api is simple and obvious.
zkon
- 488
- 1
- 6
- 16