Postfix + Sendgrid + Serverpilot - How to configure domainname etc

July 23, 2016 399 views
Email Messaging LEMP LAMP Stack DNS Ubuntu


I'm having some troubles setting up Postfix on my Ubuntu 14.04 x64.
I have connected the server with Serverpilot, so the LAMP/LEMP stack is installed automatically. Serverpilot also installs Postfix on the server, and configures it to only allow the server itself send E-mails, which is great. Source here

My problem is:

1) All E-mails sent from the server is from root root@testing. (Servername is "testing").
2) E-mails being sent, get's in the spam folder.

I found a short tutorial, on how to use Sendgrid as SMTP host. Source here

So simply adding this to /etc/postfix/main.cf. Changed the username and password, of course.

smtp_sasl_auth_enable = yes 
smtp_sasl_password_maps = static:yourSendGridUsername:yourSendGridPassword 
smtp_sasl_security_options = noanonymous 
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587

It gave an error, because relayhost is - by Serverpilot i guess - set to: relayhost =
(So nothing). I did comment out the empty relayhost, so the Sendgrid could be used, and it seems to work.

Now, where I am a little lost, is how to change the sender domain, and name, and how to avoid spam filters.

Here is the main.cf, which is configured by Serverpilot, as far as I can tell.
Now I just need to learn how to change the sender domain name, the sender name and be sure that I'm not getting into spam filters.
Anyone know what my next step is? I've been looking at this, but I am not sure this is correct:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# TLS parameters
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = MYDOMAIN.COM
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
mydestination = localhost
# relayhost =
mynetworks = [::ffff:]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
inet_protocols = all
local_transport = error:local delivery is disabled
smtp_helo_name = $myhostname.example.com

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = static:USERNAME:PASSWORD
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
3 Answers

After a lot of trial and error, and 3 servers later, still not getting the results I would like. Can anyone cast some light on this issue?

Thank you! :-)

Bumping, in hope that someone is able to help me fix this issue. :-)

anyone who uses serverpilot, please join to the unofficial slack discussion community hub, for sharing experiences about doing missing (premium) features in free plan 😉


Have another answer? Share your knowledge.