Это код, который я использую для отправки электронного письма из моего приложения Flutter:
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username, '$name')
..recipients.add('pareez.salon@example.com')
..ccRecipients.addAll([''])
..bccRecipients.add(Address(''))
..subject = 'Pareez Salon Booking'
..text = '$name //// $phoneNo //// ${widget.emailText}'
..html = "";
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}');
}
}
var connection = PersistentConnection(smtpServer);
await connection.send(message);
await connection.close();
}