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.
Related
I am trying to implement OTP verification in my Flutter app using Firebase, but I am facing an issue where the verification fails even though both the sent and entered OTP are the same.
I am using the following function to verify the OTP:
void verifyOtp({
required BuildContext context,
required String verificationId,
required String userOtp,
required Function onSuccess,
}) async {
_isLoading = true;
notifyListeners();
try {
PhoneAuthCredential creds = PhoneAuthProvider.credential(
verificationId: verificationId, smsCode: userOtp);
User? user = (await _firebaseAuth.signInWithCredential(creds)).user!;
print('signwithcredential passed');
if (user != null) {
_uid = user.uid;
onSuccess();
}
} on FirebaseAuthException catch (e) {
print('failed Userotp: $userOtp');
showSnackBar(context, e.message.toString());
_isLoading = false;
notifyListeners();
}
}
The error I am getting is "FirebaseAuthException: sms code has expired please resend the verification code to verify again."
I am new to Flutter and Firebase, so any help in fixing this problem would be greatly appreciated.
Here are couple of things I have found maybe they will work:
Check the Firebase Console to ensure that the phone number being verified is correctly set up and that the SMS code is being sent to the right number.
Make sure that the phone number is being passed in the correct format.
FirebaseAuthException is being caught correctly. Make sure the message inside the catch block is being logged or displayed to the user.
Ensure that the dependencies and packages are correctly installed and imported.
The solution is itself an error you are getting. You have to enter the code before it expire. Try to verify the otp as soon as you get the code as it's saying "I/flutter ( 9598): error on firebaseAuthexception: [firebase_auth/session-expired] The sms code has expired. Please re-send the verification code to try again. ".
I doing custom app send sms auto for users
I used many lib but it not working and my code bellow
Future<void> sendSMS(phoneNumber, message) async {
const platform = MethodChannel('sendSms');
try {
final String result = await platform.invokeMethod('send', <String, dynamic>{
"phone": phoneNumber,
"msg": message
});
print(result);
} on PlatformException catch (e) {
print(e.toString());
}
}
but when running my app throw exception with error:
MissingPluginException(No implementation found for method send on channel sendSms)
Thanks for any suport
Unless you are creating a plugin yourself, it's unlikely you need to use the invokeMethod call directly. If you use a plugin (as I expect you are) then the plugin you use will provide you with regular Dart functions or classes that you can use to do what you want the plugin to do (for example, send an SMS).
For example, if you are using the flutter_sms plugin, then per that plugin's documentation you send an SMS using
String _result = await sendSMS(message: message, recipients: recipents)
.catchError((onError) {
print(onError);
});
As you can see, you don't use invokeMethodChannel, because the plugin does that for you 'under the hood'.
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 need help trying to display a flutter error message (flutter: PlatformException(ERROR_EMAIL_ALREADY_IN_USE, The email address is already in use by another account., null)) into a string i can use in alertdialog or snackbar, but i need to be able to change the string dependent on the error.
try {
final auth = Provider.of<AuthService>(context);
await auth.signIn();
} on PlatformException catch (e) {
await PlatformExceptionAlertDialog(
title: 'The email address is already in use by another account.',
exception: e,
).show(context);
}
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.