Monday, April 4, 2016

Fix the SPF neutral message when you send email through Amazon's EC2 instance

If you got the following SPF neutral message when you send email through Amazon's EC2 instance:

Received-SPF: neutral (google.com: 51.11.171.201 is neither permitted nor denied by best guess record for domain of root@ip-171-31-11-41.us-west-2.compute.internal) client-ip=51.11.171.201;

Solution:

Set host name:

# hostnamectl set-hostname host1.example.com

# hostnamectl status

# cat /etc/hostname

Append the following string at the bottom of the file to ensure that the hostname is preserved between restarts/reboots:

# vim /etc/cloud/cloud.cfg

preserve_hostname: true

More info: https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/

Contact Amazon to add a reverse DNS record:

You can contact Amazon to request to remove email sending limitations:

https://aws.amazon.com/forms/ec2-email-limit-rdns-request

Input your Elastic IP Address 1: 51.11.171.201

Input Reverse DNS Record for EIP 1: host1.example.com (this is the Amazon EC2 instance you will be using to send out emails).

Create a sample script:

# vim test_send.php

<?php
$from    = 'info@example.com';
$to      = 'someone@abc.com';

$subject = 'test subject 6';
$message = 'test subject 6';

$headers = 'From: ' . $from . "\r\n" .
    'Reply-To: ' . $from . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Show email original:

Received-SPF: pass (google.com: best guess record for domain of user1@host1.example.com designates 51.11.171.201 as permitted sender) client-ip=51.11.171.201;

Reference:

http://aws.amazon.com/ec2/faqs/#Are_there_any_limitations_in_sending_email_from_EC2_instances
https://aws.amazon.com/premiumsupport/knowledge-center/route-53-reverse-dns/

No comments: