Profile picture Schedule a Meeting
c a n d l a n d . n e t

SMTP Set Up For Hosting Servers

Dusty Candland | | postfix, hostname, hosting

Notes for setting up SMTP for sending mail from hosting servers.


  • Make sure you have a fully qualified PTR record setup at the server provider.
  • Make sure you have an A record for the domain above pointing to the server.
  • Add an SPF record for the domain above, allowing to send from that domain.
  • Add the above domain to your sending domain's SPF record.


Setup SPF records in DNS.


v=spf1 MX ip4:<> ip4:<...> ~all


v=spf1 a -all


On the servers, make sure the hostname is set correctly.

> server-1
# Set using this:

Check IP Blacklists

If you get assigned an IP address that's on blacklists, you need to fix them OR try another IP. Check IP address at: MX Toolbox. The report contains links on how to remove.

The following lists shouldn't matter.



Assuming Postfix is already installed, we need to configure it.

dpkg-reconfigure postfix

Most of the defaults should be fine. You want an internet site that sends from the server's configured, qualified hostname. I also set up an alias for root so those emails will get forwarded to me.

Limit send from only this machine

You should have a firewall setup to make sure outside users can't get to the SMTP server, but for added protection, edit the Postfix config. Set the inet_interfaces to loopback-only.


inet_interfaces = loopback-only

Change the default sending address

If you don't actually have email set up in the domain or the subdomain, you can change the default from address to come from a domain you do have email setup for.

Append the following to the Postfix config.

echo "smtp_generic_maps = hash:/etc/postfix/generic" >> /etc/postfix/

Next we need to create the generic map.

echo "" > /etc/postfix/generic

Next, hash the generic file.

postmap /etc/postfix/generic

Finally, restart Postfix.

systemctl restart postfix


If there are already certificates for the domain, we can use those. The DO article has info on creating certificates, if you need them.

Edit /etc/postfix/ to set the paths to the certificates.


Restart Postfix again

systemctl restart postfix


Install mailutils for sending

apt install mailutils

Send a test email

echo "Test my server 1" | mail -s "test my server 1" <TO>

View the logs

tail /var/log/mail.log


How To Install and Configure Postfix as a Send-Only SMTP Server on Ubuntu 22.04

Postfix masquerading or changing outgoing SMTP email or mail address


These are webmentions via the IndieWeb and Mention this post from your site: