Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Django to send emails with AWS with a reverse DNS setup to point at a different server

I'm trying to setup Django on an AWS instance to send emails through my main website's server (non-AWS) rather than needing to use external mail services such as Mandrill, Amazon SES... etc

I first setup my main server's DNS records to point a sub-domain to the aws instance's elastic IP, for example:

mail1.website.com --> 1.1.1.1

I filed a request to have a reverse DNS record setup pointing my AWS instance's elastic IP to a sub-domain, they set it up for example:

1.1.1.1 --> mail1.website.com

Now that the reverse dns record is setup mail1.website.com should be able to be used in django to send emails without them being marked as spam.

https://docs.djangoproject.com/es/1.9/topics/email/#smtp-backend

Would using the following be enough?

EMAIL_HOST = 'mail1.website.com'
DEFAULT_FROM_EMAIL = 'test.website.com'

If I need to provide email user/password/port is it possible to set it up to login with a specific email like [email protected] but then email from [email protected] or do I have to setup the smtp settings to the root email address

No_reply email:

EMAIL_HOST = 'mail1.website.com'
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'mypasshere'
EMAIL_PORT = 465
DEFAULT_FROM_EMAIL = 'test.website.com'

or root:

EMAIL_HOST = 'mail1.website.com'
EMAIL_HOST_USER = 'root'
EMAIL_HOST_PASSWORD = 'mypasshere'
EMAIL_PORT = 465
DEFAULT_FROM_EMAIL = '[email protected]'
like image 546
Ryflex Avatar asked Apr 27 '16 22:04

Ryflex


1 Answers

I'm not sure I understand why you're trying to do this, but if your current email server is operating correctly, and you want to be able to use it to relay emails from your AWS instance, I would simply set up a VPN between AWS and your current network, and allow your AWS instance to send email that way. You're not using your email server as an external relay, so deliverability shouldn't change.

But really, the correct answer is to use SES to send emails. As long as you're not doing anything abusive, you should have no problems with deliverability.

Edit: The specific exceptions you mention (SPF_SOFTFAIL, RDNS_DYNAMIC and HELO_DYNAMIC_IPADDR) may not go away even if you set up reverse DNS for your AWS instance public IP - you are still drawing from a pool of known "dynamic" IP addresses - AWS publishes their list of IP addresses here - and I doubt may people bother to check to see if some small number of those is set up properly.

Setting up SPF to allow AWS to send on your behalf is pretty easy.

like image 58
chris Avatar answered Oct 16 '22 00:10

chris