Django send_mail() from EC2 via Gmail gives SMTPAuthenticationError - but works fine in localhost Django send_mail() from EC2 via Gmail gives SMTPAuthenticationError - but works fine in localhost django django

Django send_mail() from EC2 via Gmail gives SMTPAuthenticationError - but works fine in localhost


You probably need to unlock Captcha to enable Django to send for you: accounts.google.com/displayunlockcaptcha

Captcha are the little characters you need to type into a form to go to the next page. It's a security precaution most companies rely on.

The reason you are able to get away with it on your local host is because you are essentially the company controlling the captcha. You're telling your server, "send no matter what; it's safe." However, in this instance, Google is in control of the captcha. Since you're using Amazon, preventing the email is a way for Google to protect its servers and make sure Amazon isn't spam. By clicking the link, you are telling Google to allow all outgoing connections to happen from your email.

Does that make sense?


I have a feeling Amazon don't allow this. They really don't want you sending out mail from their servers, so they block it. It's to avoid spammers, basically, who used to send email from EC2 by the virtual truckload. I suggest that you use something like mailgun (or SES if you really love AWS, but I probably wouldn't) to handle sending email instead. There is a nice django email backend for mailgun, so you don't need to change your code at all.