-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_postfix_office365_relay
36 lines (29 loc) · 1.24 KB
/
install_postfix_office365_relay
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
echo This will install postfix and use an office365 account as a relay for outgoing emails
read -p "press enter to continue"
echo what is your office365 email address?: ; read email_address
echo what is your office365 email password?: ; read email_password
echo where should we send a test email?: ; read email_recipient
echo installing postfix
echo "postfix postfix/mailname string $(hostname --fqdn)" | debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | debconf-set-selections
apt install -y postfix mailutils
echo configuring postfix
sed -i -e '/relayhost/d' /etc/postfix/main.cf
sed -i -e '/inet_interfaces/d' /etc/postfix/main.cf
echo "/.+/ $email_address" >> /etc/postfix/sender_canonical_maps
cat <<EOT >> /etc/postfix/main.cf
smtp_sasl_auth_enable = yes
inet_interfaces = 127.0.0.1
smtp_tls_security_level = encrypt
relayhost = smtp.office365.com:587
smtp_sasl_security_options = noanonymous
sender_canonical_maps = regexp:/etc/postfix/sender_canonical_maps
smtp_sasl_password_maps = static:$email_address:$email_password
EOT
echo restarting postfix
systemctl stop postfix
systemctl start postfix
systemctl status postfix
echo sending test email
echo "body test" | mail -s "subject test" $email_recipient