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

Viewed 519

Goal

  • Deploying a landing page on Digital Ocean built with Django 3.
  • Adding my G suite account to the contact form so people can type in their email, subject, message and send it to me.

What I have done

  • I have built my contact from with the following guide.
  • I have tested it and it prints out all the parameters in the terminal as it should
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.
  • After I have finished the tutorial I have added/switched the following things to the settings.py file
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
  • I have purchased a G Suite subscription that contains G Suite SMTP relay service that can send 10'000 email/day.

ERRORS

1.After the 1st run I have received the following e-mail:

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 the 2nd run I have received the following error message in the browser (and no email)

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 seeking with google help chat and switching up a bunch of settings than running the same code again

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')
1 Answers

The problem with G-mail even if you get it working after a while google going to cut it of when it hurts the most. A better solution would be to use some of the following solutions

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