Created
September 28, 2021 20:40
-
-
Save amanjuman/4d7e1adefbb2be44518baed21c05f6ec to your computer and use it in GitHub Desktop.
SendMail with Office365 SMTP Relay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Update Packages | |
sudo apt-get update && sudo apt-get -y upgrade && sudo apt dist-upgrade -y && sudo apt-get autoremove -y | |
// Setup Hostname | |
hostnamectl set-hostname subdomain.domain.tld | |
// Create Host Record | |
sudo nano /etc/hosts | |
// Add this line | |
127.0.1.1 subdomain.domain.tld subdomain | |
// Install SendMail MTA and Mail Utilits | |
sudo apt install sendmail mailutils sasl2-bin libsasl2-modules | |
// Make Mail Dir if not exist | |
mkdir /etc/mail | |
// Create Mail Authentication Folder | |
mkdir -m 700 /etc/mail/authinfo/ | |
// Update Access with Office365 SMTP User ID Pass | |
sudo nano /etc/mail/authinfo/office365-auth | |
AuthInfo: "U:root" "I:[email protected]" "P:YOUR-PASSWORD" | |
// Generate hash file using Auth File | |
sudo makemap hash /etc/mail/authinfo.db < /etc/mail/authinfo/office365-auth | |
// Regenerate DB File | |
sudo makemap hash /etc/mail/access.db < /etc/mail/access | |
// Backup SendMail config File | |
sudo cp /etc/mail/sendmail.cf /etc/mail/sendmail_cf.backup && cp /etc/mail/sendmail.mc /etc/mail/sendmail_mc.backup | |
// Edit and Update Config File | |
sudo nano /etc/mail/sendmail.mc | |
## Office365 Config before last three line | |
define('SMART_HOST','[MX-OF-YOUR-OFFICE365-DOMAIN]')dnl | |
define('RELAY_MAILER_ARGS', 'TCP $h 25')dnl | |
define('ESMTP_MAILER_ARGS', 'TCP $h 25')dnl | |
define('confAUTH_OPTIONS', 'A p')dnl | |
define('confAUTH_MECHANISMS', 'EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl | |
TRUST_AUTH_MECH('EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl | |
FEATURE('authinfo', 'hash -o /etc/mail/authinfo.db')dnl | |
// Rebuild SendMail | |
sudo make -C /etc/mail | |
// Restart SendMail MTA | |
sudo /etc/init.d/sendmail restart | |
// Test Mail | |
/usr/sbin/sendmail -vf [email protected] [email protected] | |
From: [email protected] | |
To: [email protected] | |
Subject: Office365 SMTP Relay Test Email | |
This is a test message sent from Office365 SMTP Relay using Sendmail. | |
// Press Clt + D to Send |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment