Skip to content

Instantly share code, notes, and snippets.

@cristiroma
Last active October 11, 2024 19:22
Show Gist options
  • Save cristiroma/d0cc9f0c23bbba0994f3b263dabd7e75 to your computer and use it in GitHub Desktop.
Save cristiroma/d0cc9f0c23bbba0994f3b263dabd7e75 to your computer and use it in GitHub Desktop.
Setup a local Ubuntu 20.04 smart host to relay emails over zoho SMTP server

Configure Postfix to handle delivery

This tutorial helps configuring sending emails from the command line:

https://www.vultr.com/docs/use-zoho-as-external-smtp-server-with-postfix-on-ubuntu-20-04

Override the SMTP "From:" header

However cron still send emails to [email protected] and Zoho will bounce the message

status=bounced (host smtp.zoho.com[204.141.32.56] said: 553 Relaying disallowed as @ (in reply to end of DATA command))

https://www.linuxsysadmins.com/forcing-the-from-address-when-postfix-relays-over-smtp/

/etc/postfix/main.cf

smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = localhost
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = loopback-only
default_transport = smtp
relay_transport = smtp
inet_protocols = all

smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = smtp.zoho.com:587
smtp_use_tls = yes
sender_canonical_classes = envelope_sender, header_sender
sender_canonical_maps =  regexp:/etc/postfix/sender_canonical_maps
header_checks = regexp:/etc/postfix/header_checks

/etc/postfix/sasl_passwd

If 2FA is enabled generate an application password

smtp.zoho.com:587	[email protected]:PASSWORD

and RUN

postmap sasl_passwd

/etc/postfix/sender_canonical_maps

/.+/    [email protected]

/etc/postfix/header_checks

/From:.*/ REPLACE From: [email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment