setup smtp relay, via relayhost

Wanted to set up a relay, so I can de-/multiplex smtp to different destinations.

Set up A record for mx.destdomain.tld

In receiving dns zone, set up mx record, add spf:

rcptdomain.tld		MX	0 mx.destdomain.tld
rcptdomain.tld		TXT	v=spf1 a mx -all

Configure postfix: configure as relay, and add relayhost to send mail with

sudo apt-get install postfix libsasl2-modules

vi /etc/postfix/main.cf
myhostname = mx.destdomain.tld
mydomain = destdomain.tld
myorigin = destdomain.tld
virtual_alias_domains = rcptdomain.tld
virtual_alias_maps = hash:/etc/postfix/virtual
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_tls_security_level = encrypt
header_size_limit = 4096000
relayhost = [smtp.sendgrid.net]:587
inet_protocols = ipv4

vi /etc/postfix/virtual
user@rcptdomain.tld user@gmail.com
postmap /etc/postfix/virtual

vi /etc/postfix/sasl_passwd
[smtp.sendgrid.net]:587 apikey:KEY_GOES_HERE
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd

/etc/init.d/postfix restart

sources:

https://jichu4n.com/posts/custom-domain-e-mails-with-postfix-and-gmail-the-missing-tutorial/

https://blog.ruanbekker.com/blog/2018/11/23/setup-a-relayhost-with-postfix-to-send-mail-via-sendgrid/

https://www.spf-record.com/generator

https://www.linode.com/docs/guides/postfix-smtp-debian7/