[英]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.