简体   繁体   English

发送电子邮件到当前用户电子邮件

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

相关问题 在 firebase 云函数 flutter 中发送计划 email - Send schedule email in firebase cloud functions flutter 在 Swift 中向新的 Firebase 用户发送电子邮件验证电子邮件 - Send an email verfication email to a new Firebase User in Swift 如何在不打开 flutter 应用程序的情况下自动发送 email? - How to make Auto send email without opening the flutter app? 从发送验证邮件接收深度链接 (Flutter / Firebase) - Receive Deep Link from Send Verification Email (Flutter / Firebase) 如何在 React Native 中向用户发送 Firebase 验证 email(以便用户可以验证他们的电子邮件)? - How do you send a Firebase verification email (so that a user can verify their email) to a user in React Native? 如果用户在 flutter 中使用 email 或 gmail 登录,如何获取快照 - How to get snapShot if user have sign in with email or gmail in flutter 如何使用发送中介 WSO2 向多个电子邮件地址发送电子邮件 - How to send an email to multiple email addresses with the send mediator WSO2 如果 Flutter Firebase Auth Password Reset 中没有 Email 地址的注册用户,则不发出警告 - Do not warn if there is no registered user with Email address in Flutter Firebase Auth Password Reset Firebase 身份验证:通过 Email 查找用户 - Firebase Authentication : Lookup a user by Email 当用户使用 firebase 云功能有未读消息/通知时,是否可以向用户发送 email 摘要? - Is there a way to send email digest to a user when they have unread messages/notifications using firebase cloud functions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM