avatarKarthick Dk

Summary

The web content provides a comprehensive guide on configuring Office 365 email on a Linux system using the Postfix mail transfer agent.

Abstract

The article titled "Configure Office 365 Email on Linux using Postfix" is a technical tutorial aimed at users looking to set up email alerts from the command line on a Linux machine. It outlines the necessary steps to install and configure Postfix, an open-source mail transfer agent, to send emails through Microsoft Office 365. The guide includes detailed instructions on installing required packages, modifying configuration files, setting up email credentials, and sending test emails. It also covers optional steps for configuring multiple email accounts and provides tips for debugging with mail logs. The author, Karthick DKK, encourages readers to follow him for more content and shares his social and professional links for further engagement.

Opinions

  • The author expresses that Postfix is a popular and widely used MTA, suggesting a preference for it in the Linux community.
  • By providing a step-by-step guide, the author conveys a user-friendly approach, assuming the reader may be new to configuring Postfix for Office 365.
  • The inclusion of optional steps for multiple email configurations indicates the author's consideration for users with more complex email setup needs.
  • The author's sign-off with links to social media and a "Buy Me a Coffee" option suggests a desire to build a community and receive support for the shared content.
  • The use of the mailx command with various flags for sending emails with attachments, CC, and BCC reflects the author's practical approach to common email tasks via the command line.

Configure Office 365 Email on Linux using Postfix

Email Image by

Hey Folks✌️ welcome to another post, Here we discuss using Postfix to send email by command line.

Wondering to send alerts from the command line to Email, here we go …

Introduction:

Postfix is a popular and widely used open-source mail transfer agent (MTA) software. An MTA is responsible for routing and delivering email messages within a computer network, whether that network is the Internet or an internal network within an organization

👇Requirements:

  1. Email credentials (Microsoft 365/Gmail)
  2. Linux Machine

Step 1 — Install required packages:

# For Redhat based 
 sudo yum install postfix cyrus-sasl-plain mailx -y

# For Debian Based
sudo apt install postfix cyrus-sasl-plain mailx -y

Step 2 — Change the main.cf:

Open the /etc/postfix/main.cf file using your favorite editor(Vim/nano/) and add the below lines:

vim /etc/postfix/main.cf

relayhost = [smtp.office365.com]:587
mynetworks = 127.0.0.0/8
inet_interfaces = loopback-only
smtp_use_tls = yes
smtp_always_send_ehlo = yes
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
smtp_generic_maps = hash:/etc/postfix/generic
smtp_sender_dependent_authentication = yes
sender_dependent_relayhost_maps = hash:/etc/postfix/sender_relay

Step 2 — Set Password for Email:

Edit the password file /etc/postfix/sasl_passwd

For Office 365 Email-ID use like below

vim /etc/postfix/sasl_passwd

[smtp.office365.com]:587 [email protected]:PASSWORD

Step 3 — Configure Multiple Emails [Optional]

if you need multiple emails add them like below

vim /etc/postfix/sasl_passwd

[smtp.office365.com]:587 [email protected]:PASSWORD
[smtp.office365.com]:587 [email protected]:PASSWORD
[smtp.office365.com]:587 [email protected]:PASSWORD

Step 4— Configure the Sender Relay [ Required only for multiple Emails]

Edit /etc/postfix/sender_relay add like below

vim /etc/postfix/sender_relay

Step 5— map the files to postfix

Once all is done, map the files into Postfix. Run the below commands

$ postmap  main.cf
$ postmap  sasl_passwd
$ postmap  sender_relay

Step 6— Send Email

To send Email, run like below command.

$ echo  "This is the Test Email" | mailx -r "[email protected]"  -s "This test mail 98" [email protected]

Step 6 — Check Logs [Optional]

For debugging log file is located on /var/log/maillog.

Open log file: tail -f /var/log/maillog

✅Mailx Usage:

  • -a → add attachment
  • -b → add Bcc Email
  • -c → add CC Email
  • -r → From Email Address
  • -s → Subject of the Email

Taking the message from a file

$ mailx -s "Test Mail by mailx" [email protected] < file.txt

Sending the same Mail to Multiple Recipients:

We can send the same email to multiple receivers (not by cc or bcc) as follows:

$ mailx - s "Test Mail by mailx" [email protected], [email protected] < file.txt

Adding Attachments

$ mailx - s "Test Mail by mailx" [email protected] -a File.txt

Adding CC & BCC

$ mail - s "A mail sent using mailx" [email protected] -c [email protected] -b [email protected]

Thanks for reading & Follow for More ✌️

Medium — https://medium.com/@karthidkk123 LinkedIn — https://www.linkedin.com/in/karthick-dkk/ Instagram — https://www.instagram.com/karthick_dkk_dk/ GitHub — https://github.com/karthick-dkk

By Me Coffee 👇

Postfix
Centos
DevOps
Devops Practice
Devops Tool
Recommended from ReadMedium