The purposes of this gist:
- setup an smtp smarthost/relay that can send mail to Exchange Online 365 Office Outlook M365 (they keep renaming it)
- setup postfix each proxmox host and backup server to use this relay
- require the relay does authentications from devices like pve and pbs - having an open SMTP relay inside the network is not something i can bring myself to do
- And incidentally document the istall of a HA LXC based on debian
Also i am aware i probably over engineered this - after i had done this i realized postfix as shipped in PVE and PBS was attmepting to contact a variety of servers in my network based on DNS - i still haven't figured the logic out for that.... maybe all i needed was a relay and an MX record (and no config on PVE and PBS?)
TODO
- switch to TLS to protect creds in transit (this is gonna need certbot in the postfix VM)
this gist is part of this series
- You have valid Office 365 Business Plan of some sort
- You have a mailbox called something like [email protected] (this is must be a full mailbox, shared mailbox will not work)
- you haven't disabled SMTP Auth - See this MS guide if the steps below can't be done.
- Open the Microsoft 365 admin center and go to Users > Active users.
- Select the user, and in the flyout that appears, click Mail.
- In the Email apps section, click Manage email apps.
- Set Authenticated SMTP setting to checked (aka enabled)
When you're finished, click Save changes.
- Navigate to
Datacenter > pve node - select your local or ceph storage where you store ISOs and CT templates (for me this is my ISOs-Templates disk)
- click
CT Templates - click
templates - donwnload
debian-12-standard_12.0-1_amd64 - wait for download to finish
- click
create CTin upper right of pve console - choose a node (any node will do if you followed all my other gists)
- give it a CT ID
- hostname =
postfix.mydomain.com - give is a password and optionally your ssh public key (if you want to login via an ssh client)
- click
next - choose your storage location and the debian 12 template downloaded earlier
- click
next - For storage set it to your ceph rbd (in my case vm-disks) (if you only have local storage use that)
- leave other settings at default
- click
next - memory leave as defaults and click
next - set networking tab as you prefer and click
next(also don't forget to put the name of the client in your local DNS server - if you don't have a local DNS sever make one) - DNS tab - i prefer use host settings change as you see fit and click
next - check start after created and click finish
- this can be skipped if you don't have a HA cluster
- navigate to
Datacenter > HA - click
addunder resources - select the containe VMID in the VM box
- add to a cluster group e.g
ClusterGroup1(this was created in an ealier gist) - set requested state =
started - click
add
- login to container you just created
- As always issue a
apt update && apt upgrade - Install requirements with
apt install postfix libsasl2-modules mailutils rsyslog - add a new user to the system with
add user system - give the user a password with
passwd system
- edit the postifix config file with
nano /etc/postfix/main.cf - change the following
mydomain = mydomain.com
myhostname = postfix.mydomain.com
relayhost = smtp.office365.com:587
compatibility_level = 0
- add the following
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CApath = /etc/ssl/certs
smtp_sasl_security_options = noanonymous, noplaintext
smtp_sasl_tls_security_options = noanonymous
mynetworks = 127.0.0.0/8, 192.168.1.0/24
inet_interfaces = all
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = smtpd
smtpd_sasl_security_options = noanonymous
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions = permit_sasl_authenticated,reject_unauth_destination,check_relay_domains
- save the file
- create a password file with
nano /etc/postfix/sasl_passwd - Add the following:
smtp.office365.com [email protected]:mypassword
- save the file
- run
postmap /etc/postfix/sasl_passwd - edit the aliases file with
nano /etc/aliases
postmaster: root
webmaster: root
root: [email protected]
system: [email protected]
- save the file
- run
newaliases - reload postfix with
postfix reload
echo "this is a test email" | mail -s "pve node X test email" [email protected] -a "FROM:[email protected]"
Replace my placeholders to match your env
apt install libsasl2-modules- edit the postifix config with
nano /etc/postfix/main.cf - change these lines
relayhost = postfix.mydomain.com:25
compatibility_level = 3.6
- add these lines
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
- save the file
- create the sasl password file
nano /etc/postfix/sasl_passwd - add the following
postfix.mydomain.com system:<password>
- save the file
- run
postmap /etc/postfix/sasl_passwdto process the password file - restart postfix service
systemctl restart postfix
Test by issuing this comamnd
echo "this is a test email" | mail -s "pve node X test email" [email protected] -a "FROM:[email protected]"
Replace my placeholders to match your env
- Navigate to
Datacenter > options - doubleclick
email from address - set emal as
[email protected]and clickok
(repeat on PBS in Configuration > Other)
corrected typo on the name of main.cf (original said main.cfg)