Skip to content
Geek is the Way!
Menu
  • Forums
  • Sobre o blog
  • Contato
  • English
Menu

Configuring E-mail client with Postfix on your Linux Ubuntu

Posted on December 24, 2022December 30, 2024 by Thiago Crepaldi

Last Updated on December 30, 2024 by Thiago Crepaldi

Everytime we spawn a new server, it is a good idea to enable email services on it so that they can a means to reach us and notify of important events, such as software or hardware failures. In this post we are going to enable configure E-mail on Linux distros using postfix. I will use Ubuntu as an example, but it should work for most distros with minor path changes to postfix installation dir. The email server will be backed my GMail, which also works if you have Google Suite and a custom domain, such as yourdomain.com!

Install OS dependencies

The first step is to install a library that will be used to support GMail authentication. Go to Server view >> Datacenter and select your server. Next, click at Shell button

# apt update
# apt install -y postfix libsasl2-modules

Optional: Create app password for 2FA GMail accounts

If your GMail account has 2FA configured, go to App Passwords and generate a new password just for Proxmox

  • Select app: Mail
  • Select device: Other
  • Select the app and device you want (…): Proxmox

Click on Generate and take note of this password

Setting GMail credentials

Now that all dependencies are installed and you have your password, let’s do the actually setting. Make adjustment to the snippet below to add your actual email and password separated by a colon.

# echo "smtp.gmail.com youremail@gmail.com:yourpassword" > /etc/postfix/sasl_passwd
# postmap hash:/etc/postfix/sasl_passwd
# chmod 600 /etc/postfix/sasl_passwd

With your favorite editor, hopefully vim or nano, edit Postfix configuration file.

# vim /etc/postfix/main.cf

Append the following to the end of the file

 relayhost = smtp.gmail.com:587
 smtp_use_tls = yes
 smtp_sasl_auth_enable = yes
 smtp_sasl_security_options =
 smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
 smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem
 smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
 smtp_tls_session_cache_timeout = 3600s

Before saving the config file, also comment out the existing “relayhost =” line by updating it to “# relayhost =”. This is needed because the snippet you appended already sets this line to Google’s email and we can’t have duplicate settings.

At this point, all configuration is done. Just reload postfix and test it

# postfix reload
# echo "my msg" | mail -s "my subject" anotheremail@gmail.com

postfix/postfix-script: refreshing the Postfix mail system

For the test email, you have to use a destination that is different than the email account you used to configure the server. If everything went well, you should get the email in your inbox in a couple seconds.

Share this:

  • Tweet

Related

3 thoughts on “Configuring E-mail client with Postfix on your Linux Ubuntu”

  1. prad says:
    June 13, 2023 at 3:51 AM

    hi I’m getting the following error in the logs : This mail is unauthenticated, which poses a security
    risk to the 550-5.7.26 sender and Gmail users, and has been blocked. The sender
    must 550-5.7.26 authenticate with at least one of SPF or DKIM. For this message
    , 550-5.7.26 DKIM checks did not pass and SPF check for

    do I need to set dkim for my server ?

    Reply
    1. Thiago Crepaldi says:
      June 13, 2023 at 8:50 AM

      That seems to be a new policy from Gmail. I am sure I did this without SPF and DKIM at some point. Nonetheless, SPF and DKIM are simple to configure and increase your chances of delivery by Google. That is a topic I could write about soon

      Reply
  2. Pingback: Deploying a public Vaultwarden instance on a Proxmox LXC container using HAProxy on pfSense - Geek is the Way!

Leave a ReplyCancel reply

LIKED? SUPPORT IT :)

Buy Me a Coffee


Search


Categories

  • Cooking (1)
  • Homelab (79)
    • APC UPS (6)
    • pfSense (40)
    • Proxmox (20)
    • Shopping (1)
    • Supermicro (2)
    • Synology NAS (8)
    • Ubiquiti (6)
    • UDM-Pro (4)
  • Random (3)
  • Wordpress (1)

Tags

Agentless monitoring (3) AP9631 (3) Apache2 (3) APC UPS (6) Bind9 (3) certificates (5) crontab (2) DDNS (5) debian (3) DNS (7) DSM (6) DuckDNS (2) Dynamic DNS (4) en_US (2) Firewall (9) gmail (3) LDAP (2) Let's Encrypt Certificates (7) monitoring (18) networking (21) PBS (3) pfsense (43) port forwarding (3) proxmox (17) proxmox backup server (3) proxmox virtual environment (16) pve (5) rev202207eng (76) security (28) SNMP (4) SNMPv1 (3) ssh (4) SSL (6) subnet (2) Synology (7) udm-pro (5) unifi (6) unifi controller (3) unifi switch (2) UPS (5) VLAN (4) vpn (9) wifi (4) Zabbix (18) Zabbix Agent2 (11)

See also

Privacy policy

Sitemap

©2025 Geek is the Way! | Design by Superb