i want little ask about sending email with flutter . I using https://pub.dev/packages/flutter_email_sender#-readme-tab- for sending email.
Sending Function
Future sendEmail(String subject,String body,List<String> recipients) async{
final Email email = Email(body: body,subject: subject,recipients: recipients);
String platformResponse;
try {
await FlutterEmailSender.send(email);
platformResponse='success';
} catch (e) {
platformResponse = e.toString();
}
print(platformResponse);
}
View.dart
Center(
child: RaisedButton(
onPressed: () => _sendMail(),
child: Text('send'),
),
)
void _sendMail() async {
return await api.sendEmail(widget.namaUpdate, widget.jurusanUpdate,['zefry.reynando#gmail.com']);
}
it's possible sending email automatic without open gmail app first ? (Like in codeigniter)
i trying using another package but always open gmail app first. or this how it works?
Thanks
You're not likely to find a package that sends email out without either configuration or a visible mail client. That app would not by approved by either Apple or Google, because it might be a source of SPAM.
Related
this is the function to send an WhatsApp message (or just launch the WhatsApp with the message)
in the Cipher.dart
void sendCodeByWhatsApp(
String phone,
String message,
) async {
String url() {
if (Platform.isAndroid) {
return "https://wa.me/$phone/?text=$message";
} else {
return "https://api.whatsapp.com/send?phone=$phone=$message";
}
}
if (await canLaunchUrl(Uri.parse(url()))) {
await launchUrl(Uri.parse(url()));
} else {
throw 'Could not launch ${url()}';
}
}
and here I use it:
ElevatedButton(
child: const Icon(Icons.whatsapp, color: Colors.white,),
onPressed: (){
Cipher().sendCodeByWhatsApp(encrypt.encrypt, phone.text);
},
),
when adding a number and message, just open a page with WhatsApp logo, tells me:
we couldn't find the page you were looking for
Refer to this to get how to use the link properly link
There may also be an error if the number includes the country code like
+1 0123456789
Will give an error. The phone should not include the country code.
after doing some search, finally found the solution:
same code above, but the URL should be like this:
"whatsapp://send?phone=$phone&text=${Uri.parse(message)}";
for android, and it is working like a charm...
Change the ? to & and it will open the WhatsApp page in the browser for you
"https://wa.me/$phone/&text=$message";
I was building an email verification page on my flutter app for users to verify their emails before they can sign in. So in the verification page, I have a button that allows the users to resend the verfication email after 5 seconds from the time they sent.
Future sendVerificationEmail() async {
try{
final user = FirebaseAuth.instance.currentUser!;
await user.sendEmailVerification();
setState(() => canResendEmail = false);
await Future.delayed(const Duration(seconds: 5));
canResendEmail = true;
}catch (e) {
Utils.showSnackBar(e.toString());
}
}
...............................
ElevatedButton.icon(
icon: const Icon(Icons.email, size: 32),
label: const Text("Resend email"
),
onPressed: canResendEmail ? sendVerificationEmail : null,
),
But then the problem is when I try to resend the email again, most of the time i get the error which says:
[firebase-auth/too many requests] We have blocked all requests from this device due to unusual activity. Try again later.
Well, I understand that this is great for security but its just not consistent at all. Like sometimes I can resend 5 emails within 30 seconds and sometimes it will keep showing this error for more than 2 minuetes.
My question is whether i can set some rules in the firebase to make that I can like send certain number of email requests per seconds or like at least get to know what is the exact time that I need to wait before I can send a request again instead of this random situation where sometimes I can send multiple requests within short time.
I am trying to implement a password reset function that incorporates a SnackBar to display either success or error messages. The code shown below produces both the success message and the various error messages, as appropriate - but I never receive the password reset email from the Firebase service. I'm not sure if it's a Firebase setup issue or an issue with the code.
Future resetPassword() async {
try {
await FirebaseAuth.instance
.sendPasswordResetEmail(email: _emailController.text.trim());
_showSnackBar('Password reset link sent');
} on FirebaseAuthException catch (e) {
_showSnackBar(e.message.toString());
return;
}
}
Future<void> _showSnackBar(String msg) async {
final snackBar = SnackBar(
content: Text(msg),
);
ScaffoldMessenger.of(context).showSnackBar(snackBar);
}
Disregard. Code seems to work fine - problem was either with Firebase Auth service or my internet service provider last night. All good now.
Make sure to check your spam, because if did not add authorize rules in firebase then the reset link goes in spam mail.
.
I have a problem when send email in flutter(IOS). I use flutter_email_sender lib.
Future<void> send() async {
final Email email = Email(
body: _bodyController.text,
subject: _subjectController.text,
recipients: [_recipientController.text],
attachmentPath: attachment,
isHTML: isHTML,
);
await FlutterEmailSender.send(email);
}
button... onPressed: send()
==> Unhandled Exception: PlatformException(not_available, No email clients found!, null)
I had the same issue on iOS. It was caused because iOS hadn't set up the default Mail Application. Did you setting it on Setting app?
https://pub.dev/packages/mailer
I'm using this for both Android/iOS. No issue on either of them.
It's a well maintained package.
The url_launcher package (https://pub.dev/packages/url_launcher) doesn't seem to work for Flutter for Web. The following code prints "test url1" but nothing happens afterwards.
How can I implement mailto: like functionality in Flutter for Web which causes the default email app to open with a prepopulated 'to:' email address?
FlatButton(
onPressed: _mailto, //() => {},
padding: EdgeInsets.all(3.0),
child: _contactBtn(viewportConstraints),
)
_mailto() async {
const url = 'mailto:support#email.com?subject=Product Inquiry&body=';
print("test url1");
if (await canLaunch(url)) {
print("test url2");
await launch(url);
} else {
print("test url3");
throw 'Could not launch $url';
}
}
After experimenting a little I found a way to make url_launcher work with web.
Don't use canLaunch(url). Instead, just use launch(url), but wrap it in try-catch block. This way you should be safe and the email link will work. For catch you can just copy the email to clipboard and notify the user about that with a snackbar or smth. Probably not the best solution, but a good one, till we get something better.
Here is the sample code, so that you see what I mean:
void _launchMailClient() async {
const mailUrl = 'mailto:$kEmail';
try {
await launch(mailUrl);
} catch (e) {
await Clipboard.setData(ClipboardData(text: '$kEmail'));
_emailCopiedToClipboard = true;
}
}
import 'package:mailto/mailto.dart';
// For Flutter applications, you'll most likely want to use
// the url_launcher package.
import 'package:url_launcher/url_launcher.dart';
// ...somewhere in your Flutter app...
launchMailto() async {
final mailtoLink = Mailto(
to: ['to#example.com'],
cc: ['cc1#example.com', 'cc2#example.com'],
subject: 'mailto example subject',
body: 'mailto example body',
);
// Convert the Mailto instance into a string.
// Use either Dart's string interpolation
// or the toString() method.
await launch('$mailtoLink');
}