How to read your email messages managed by postfix using Linux shell

What is postfix?

Postfix is a popular open-source mail transfer agent (MTA) used for routing and delivering email. It's commonly used on Unix-like systems such as Linux. Postfix is designed to be fast, secure, and efficient, making it a popular choice for handling email delivery on servers.

Why should I read an email via commandline?

Imagine you have a website hosted on Linux without any GUI to manage the emails. However, for some reasons you need to provide an email in your domain and you need to obtain the emails sent to this address. Here, you will need to be able to read emails form your Linux commandline.

Fist step, where are your emails stored?

First of all you will need to find where your emails are located.

This is adjusted in /etc/postfix/main.cf in the parameter of home_mailbox or mail_spool_directory.

You can use this shortcut command in the Linux shell on your remote server machine to obtain that location:

cat /etc/postfix/main.cf | grep -E 'home_mailbox|mail_spool_directory'

For me, the result is as follows:

home_mailbox = Maildir/

Hence, I look for ~/Maildir/ to find the emails:

ls Maildir/
cur  new  sent  tmp

You can read a particular raw email from the new folder. Raw email files can be so confusing.

For checking the sender of any particular email file, you can use a command similar to this

grep "From: " ~/Maildir/new/1714928557.Vfc01I1f875dM451614.example.com

where the file 1714928557.Vfc01I1f875dM451614.example.com is one of the files observed in the new folder.

linux
email
postfix
Software and digital electronics / IT
Posted by admin
2024-05-05 17:10
×

Login

No account?
Terms of use
Forgot password?