'How to Sending sms and email using Dart (Flutter)?
I am trying to build and app in flutter which sends email and SMS. Purpose is to reset password (forgot Password). But I am not able to find a suitable package for it. The email or SMS should be sent with out user interaction once they click reset password. The SMS and email will be sent from their mobile to the very same number or email.
Any alternate suggestions?
Solution 1:[1]
For Email, you can use this mailer package => https://pub.dev/packages/mailer
Update: If this function didn't work then lower your mailer package version.
Example:
Future<void> sendMail(String name, String otp, String recipientEmail) async {
// ignore: deprecated_member_use
SmtpServer smtpServer = gmail('yourEmail', 'Password');
Message message = Message()
..from = address('yourEmail', 'UserName')
..recipients.add(recipientEmail)
..subject = 'Any Text.'
..html = "Any Text.";
try {
final sendReport = await send(message, smtpServer);
PrintLog.printMessage('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
PrintLog.printMessage('Message not sent. ' + e.toString());
for (var p in e.problems) {
PrintLog.printMessage('Problem: ${p.code}: ${p.msg}');
}
}
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
}
For SMS, you can use Url Launcher Package => https://pub.dev/packages/url_launcher
Example:
_textMe() async {
if (Platform.isAndroid) {
const uri = 'sms:YourNumber?body=hello%20there';
await launch(uri);
} else if (Platform.isIOS) {
// iOS
const uri = 'sms:YourNumber&body=hello%20there';
await launch(uri);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |