How do I change the hostname and from address on my Amazon EC2 instance when using AuthSMTP?

When you a launch a new Amazon EC2 instance using Amazon Linux or other similar Linux / Unix operating system it is assigned a default hostname which consists of your instance's IP address, your EC2 region and Amazon's internal hostname.

This typically looks something like:

ip-12-34-56-78.us-east-1.compute.internal

You may find that some mailer agents / programs default to using this as the from address, as this is not a valid public domain name it cannot be authorized on an AuthSMTP account.

There are number of ways to resolve this but it does depend on which program you are using to send your email.

Change the server hostname

Amazon have an article in their EC2 documentation that explains how to do this:

http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-hostname.html

The steps are specific to Amazon Linux but will be similar for other operating systems.

Change default hostname for Sendmail

If you need to setup Sendmail to use AuthSMTP as a smart host please see our Sendmail smart host setup guide.

Edit the main config file:

vi /etc/mail/sendmail.mc

Append:

define('confDOMAIN_NAME','mail.example.com')dnl

Run:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf; /etc/init.d/sendmail restart

Depending on how you send your email you may also need to repeat / alternate that process with / to the Sendmail 'submit' config files.

Change default hostname for Postfix

If you need to setup Postfix to use AuthSMTP as a smart host please see our Postfix smart host setup guide.

Edit the main config file:

vi /etc/postfix/main.cf

Append:

smtp_generic_maps = hash:/etc/postfix/generic

...and save the file.

Edit the 'generic' file:

vi /etc/postfix/generic

...and append:

root@ip-xx-xx-xx-xx.us-east-1.compute.internal root@example.com

...and save the file.

Hash the file using Postmap:

postmap /etc/postfix/generic

...and then restart Postfix:

/etc/init.d/postfix restart