Postfix M365 (Office 365) relay as LXC¶
The purposes of this gist:
1. setup an smtp smarthost/relay that can send mail to Exchange Online 365 Office Outlook M365 (they keep renaming it)
2. setup postfix each proxmox host and backup server to use this relay
3. 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
4. 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
Prepare Exchange Online (or whatver it is called this week)¶
ASSUMPTIONS:¶
- You have valid Office 365 Business Plan of some sort
- You have a mailbox called something like system@mydomain.com (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.
INSTRUCTIONS:¶
- 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.
Install Debian LXC (HA Mode)¶
Download CT Template¶
- 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
Create CT¶
- 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
Make HA¶
- 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
Install and Configure Postifx Relay to connect to M365¶
- login to container you just created
Prepare the Container¶
- 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
Configure Postfix¶
- edit the postifix config file with
nano /etc/postfix/main.cf - change the following
- 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:
- save the file
- run
postmap /etc/postfix/sasl_passwd - edit the aliases file with
nano /etc/aliases - save the file
- run
newaliases - reload postfix with
postfix reload
Test by issuing this comamnd¶
echo "this is a test email" | mail -s "pve node X test email" to@whomever.com -a "FROM:system@mydomain.com"
Replace my placeholders to match your env
Confgure postfix on each proxmox node and backup server¶
apt install libsasl2-modules- edit the postifix config with
nano /etc/postfix/main.cf - change these lines
- add these lines
- save the file
- create the sasl password file
nano /etc/postfix/sasl_passwd - add the following
- save the file
- run
postmap /etc/postfix/sasl_passwdto process the password file - restart postfix service
systemctl restart postfix
Test¶
Test by issuing this comamnd
echo "this is a test email" | mail -s "pve node X test email" to@whomever.com -a "FROM:system@mydomain.com"
Replace my placeholders to match your env
set from name on on cluster¶
- Navigate to
Datacenter > options - doubleclick
email from address - set emal as
system@mydomain.comand clickok
(repeat on PBS in Configuration > Other)