sendMail static method
Send an email using Gmail SMTP.
@param body The email body content @param title The email subject @param email The recipient's email address @return null if successful, or error message if an error occurs
Implementation
static Future<String?> sendMail(
{required String body,
required String title,
required String email}) async {
String username = 'dev.3tit@gmail.com';
String password = 'axgk hevk wcvj qnye';
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username, 'Dev 3T')
..recipients.add(email)
..subject = title
..text = body;
try {
await send(message, smtpServer);
return null;
} on MailerException catch (e) {
log('Message not sent. ${e.message}');
for (var p in e.problems) {
log('Problem: ${p.code}: ${p.msg}');
}
return e.message;
}
}