[英]send email to current user email in flutter
在此代码中,将电子邮件发送到特定电子邮件,但我想将电子邮件发送到当前用户电子邮件,我将我的项目与 firebase 连接。
sendMail() async {
String username = 'example@gmail.com';
String password = 'axneqgkraxm';
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username, 'testing')
..recipients.add('uu500oi@gmail.com')
..subject = 'Receipt :: ${DateTime.now()}'
..text = 'This is the plain text.\nThis is line 2 of the text part.'
..html = html
.replaceFirst('{{title}}', 'this will be the title')
.replaceFirst('{{price}}', '20')
.replaceFirst('{{hours}}', '2:00 PM')
.replaceFirst('{{description}}', 'this is description');
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print(e);
print('Message not sent.');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
谁能解决???
试试下面的代码:
sendMail() async {
if (FirebaseAuth.instance.currentUser != null) {
String username = 'example@gmail.com';
String password = 'axneqgkraxm';
final smtpServer = gmail(username, password);
final message = Message()
..from = Address(username, 'testing')
..recipients.add(FirebaseAuth.instance.currentUser?.email)
..subject = 'Receipt :: ${DateTime.now()}'
..text = 'This is the plain text.\nThis is line 2 of the text part.'
..html = html
.replaceFirst('{{title}}', 'this will be the title')
.replaceFirst('{{price}}', '20')
.replaceFirst('{{hours}}', '2:00 PM')
.replaceFirst('{{description}}', 'this is description');
try {
final sendReport = await send(message, smtpServer);
print('Message sent: ' + sendReport.toString());
} on MailerException catch (e) {
print(e);
print('Message not sent.');
for (var p in e.problems) {
print('Problem: ${p.code}: ${p.msg}');
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.