[英]send email to current user email in flutter
In this code send email to specific email but I want send email to current user email I connect my project with firebase.在此代码中,将电子邮件发送到特定电子邮件,但我想将电子邮件发送到当前用户电子邮件,我将我的项目与 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}');
}
}
anyone can solve it???谁能解决???
You can get the email address of the current user from Firebase Authentication with:您可以通过 Firebase 身份验证获取当前用户的电子邮件地址:
if (FirebaseAuth.instance.currentUser != null) {
print(FirebaseAuth.instance.currentUser?.email);
}
Also see the Firebase documentation on getting the current user profile and the reference document for Firebase's User
object .另请参阅有关获取当前用户配置文件的 Firebase 文档和 Firebase 的User
对象的参考文档。
Try the following code:试试下面的代码:
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.