使用 Django 3、G Suite 联系表格 - 电子邮件发送错误

Contact Form with Django 3, G Suite - email sending error

目标

我做了什么

Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: helllo
From: customeremail@gmail.com
To: admin@example.com
Date: Tue, 17 Mar 2020 14:29:40 -0000
Message-ID: <12121212121212.1222212121212.1212121212121212@mymachinename.local>
This is the message.
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp-relay.gmail.com' 
EMAIL_HOST_USER = 'mayname@mycompanydomain.com' 
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

错误

1.After 第一 运行 我收到了以下邮件:

Sign-in attempt was blocked
myname@businessemaildomainname.com
Someone just used your password to try to sign in to your account from a non-Google app. Google blocked them, but you should check what happened. Review your account activity to make sure no one else has access.
Check activity

2.After 第二个 运行 我在浏览器中收到以下错误消息(没有电子邮件)

SMTPAuthenticationError at /email/
(535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials 121sdgsdf.12 - gsmtp')
Request Method: POST
Request URL:    http://127.0.0.1:8000/email/
Django Version: 3.0
Exception Type: SMTPAuthenticationError

3.After 寻求 google 帮助聊天和切换一堆设置,而不是 运行再次使用相同的代码

SMTPSenderRefused at /email/
(111, b"5.7.0 Mail relay denied [1111:1a1a:111a:1111:1aaa:aaa:a11aa:aa11a]. 
Invalid\n5.7.0 credentials for relay for one of the domains in: 
myusername.local,\n5.7.0 mydomainname.com (as obtained from HELO and MAIL FROM).\n5.7.0 
Email is being sent from a domain or IP address which isn't registered\n5.7.0 
in your G Suite account. Please login to your G Suite account and\n5.7.0 
verify that your sending device IP address has been registered within\n5.7.0 
the G Suite SMTP Relay Settings. For more information, please visit\n5.7.0
https://support.google.com/a/answer/6140680#maildenied 1aa1a1a1a1k.111 - gsmtp", 'thecontactfillercustomeremail@gmail.com')

G-mail 的问题,即使您在一段时间后可以正常使用它 google 也会在最痛的时候停止使用它。更好的解决方案是使用以下一些解决方案

  • sendgrid.com
  • mailjet.com
  • icontact.com
  • mailgun.com