【问题标题】:Failed to send email using gmail as client (django, graphene)使用 gmail 作为客户端(django、石墨烯)发送电子邮件失败
【发布时间】:2021-07-26 15:52:20
【问题描述】:

我正在尝试在我的 django 项目中将电子邮件客户端设置为 gmail。当我注册用户时,它给了我以下错误:

{
  "data": {
    "register": {
      "success": false,
      "errors": {
        "nonFieldErrors": [
          {
            "message": "Failed to send email.",
            "code": "email_fail"
          }
        ]
      },
      "token": null
    }
  }
}

我的 settings.py 看起来像这样

EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend"
EMAIL_HOST = "smtp.gmail.com"
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = "youremail@gmail.com"
EMAIL_HOST_PASSWORD = "yourpassword"

我已经启用了谷歌的两步验证。

我的 AuthMutation 如下所示:

class AuthMutation(graphene.ObjectType):
    register = mutations.Register.Field()
    verify_account = mutations.VerifyAccount.Field()
    login = mutations.ObtainJSONWebToken.Field()
    update_account = mutations.UpdateAccount.Field()
    resend_activation_email = mutations.ResendActivationEmail.Field()
    send_password_reset_email = mutations.SendPasswordResetEmail.Field()
    password_reset = mutations.PasswordReset.Field()
    password_change = mutations.PasswordChange.Field()

提前感谢惊人的 stackoverflow 社区

【问题讨论】:

    标签: django graphql gmail


    【解决方案1】:

    只需将以下行添加到 GRAPHQL_AUTH:

    'EMAIL_FROM':'youremail@gmail.com',
    

    【讨论】:

      猜你喜欢
      • 2017-02-09
      • 1970-01-01
      • 2018-01-13
      • 2020-02-14
      • 1970-01-01
      • 2023-03-30
      • 2018-09-04
      • 1970-01-01
      • 2019-01-22
      相关资源
      最近更新 更多