How do I send email using flutter mailer package without enabling 'less secure app access' in google security. I want something similar like sending mail in NodeJS. Can anyone send a code snippet to understand better?
I have tried this
sendMail async() {
String username = '[email protected]';
String password = 'password'; // Don't want to write my password in code
// Creating the Gmail server
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username)
..recipients.add('[email protected]') //recipient email
..subject = 'Subject line' //subject of the email
..text = 'This is the plain text.\nThis is line 2 of the text part.';
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' +
sendReport.toString());
} on MailerException catch (e) {
print('Message not sent. \n' +
e.toString());
}
If there is a way to just send mails without mentioning password , I would be glad to know it.