Postfix Configuration: Determining the Appropriate Settings for myhostname and mydestination

To restrict incoming emails to specific email addresses, I updated the relevant line on my server. This configuration is effective for both internal and external emails. When sending emails locally, I use the recipient’s username without the domain name (since the correct domain is already specified). To send emails via SMTP, I can either use the domain name or the subdomain name. Unfortunately, when a cron job is triggered, the email is sent via SMTP to [email protected] instead of being delivered locally to [email protected] as intended.


Question:

I am running Ubuntu on a web server that requires email sending through sendgrid. The server is not designed to receive external emails and has the following hostname configuration.

/etc/hostname = example
/etc/hosts = www.example.com.int example (the fqdn has no entry in DNS server)

The load balancer, with the DNS set as www.example.com, will be used to access the web server.

Which setting is preferred for

main.cf

?

myhostname = www.example.com.int
mydestination = www.example.com.int, example.com.int, localhost

OR

myhostname = www.example.com
mydestination = www.example.com, example.com, localhost


Solution 1:

The default value for

$myhostname

is equivalent to the FQDN of the system. To ensure proper configuration, it should be set to something like

hostname.example.com

. You can refer to the manpages of

hostname

and its related components to configure it accurately. The

$myhostname

variable is utilized in several other parameters such as

smtp_helo_name

, which must be a valid and correct FQDN. Failure to do so may result in the rejection of your email by multiple servers or, at the very least, be labeled as spam. Rejecting wrong helos is a useful technique for minimizing spam.

According to Craig Watson,

mydestination

loses its significance if there is no mail delivery to the location. However, it is strongly advised to check the mail of server administrators such as webmaster and postmaster.

Don’t forget to add this server to your DNS SPF entry.


Solution 2:


The FQDN of the server should be specified as the value for

myhostname

.

In case your server doesn’t receive any emails, you can set

mydestination

to

localhost

without any worries. This is because the

mydestination

directive is responsible for managing the domains that Postfix will try to deliver locally.

Refer to the Postfix documentation at http://www.postfix.org/ for more information on the `mydestination` parameter.

Frequently Asked Questions