Sendgrid is useful to send email in a homelab setting if you're sending less than 100 emails/day (in my case it's currently 1, when backups complete each day)
First we want to create a sendgrid account, and get our DNS setup following sendgrids guides.
In Proxmox, we need to install a couple things in the terminal:
sudo apt install postfix postfix-pcre mailutils libsasl2-modules
Edit the /etc/postfix/main.cf file and add/update the following lines
# See /usr/share/postfix/main.cf.dist for a commented, more complete version
myhostname=your_domain.com
smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
relayhost = [smtp.sendgrid.net]:587
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
Create a file /etc/postfix/sasl_passwd with the following line
[smtp.sendgrid.net]:587 apikey:your_api_key_here
emails with no specified "from" header get applied root@your_domain.com. Use this file to rewrite the From to an address of your choosing
If you don't want to do this, you can skip this file, but you also need to comment out the smtp_header_checks
line in main.cf
/^From:.*/ REPLACE From: proxmox01 <proxmox01@your_domain.com>
source link
Create the postmaps of these files
postmap /etc/postfix/sasl_passwd
postmap /etc/postfix/smtp_header_checks
Now restart and enable postfix
systemctl restart postfix
systemctl enable postfix
If everything is setup correctly you should be able to send a test email
echo "This is a test email from Proxmox using SendGrid" | mail -s "SendGrid Test" [email protected]
To check the logs to see if postfix succeeded or had any errors (use spacebar to get to the end of the journalctl):
journalctl -t postfix/smtpd -t postfix/smtp
source link