This code returns "Message not sent" in run and not send message to email.
I want to send auto mail to gmail with sendMail function.
I copied this code from dard pub and github.
sendMail() async {
String username = '*******@gmail.com';
String password = '*********';
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username)
..recipients.add('********@gmail.com')
..subject = 'Test Dart Mailer library :: 😀 :: ${DateTime.now()}'
..text = 'This is the plain text.\nThis is line 2 of the text part.'
..html = "<h1>Test</h1>\n<p>Hey! Here's some HTML content</p>";
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print('Message not sent.');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
}
Solution 1: LucasACH
The message wont be sent, because you are using your normal Gmail password. Just need to generate an app password. An app password is a 16-digit passcode that gives a non-Google app or device permission to access your Google Account.
Follow these steps for signing in using app passwords. Hope this hepls!