How to Enable Logging for Email Subject Fields in Postfix Maillog

Postfix MTA basically just capture ‘From’ and ‘To’ field while the subject is not logged to the maillog. There are simple steps to enable logging of the e – mail subject in postfix maillog. This will very useful for email administrators when performing troubleshooting of problems related with email.

1. Assume that postfix has been installed. Open the postfix main configuration file :
# vi /etc/postfix/main.cf
2. Uncomment the following :
..
..
header_checks = regexp:/etc/postfix/header_checks
..
..
3. Open /etc/postfix/header_checks file and add the following line at the bottom :
# vi /etc/postfix/header_checks
..
..
/^Subject:/     WARN
4. Run postmap to apply the new configuration in /etc/postfix/header_checks :
# postmap /etc/postfix/header_checks :
5. Restart or reload postfix configuration :
# service postfix restart

or

# postfix reload
6. Test send email with subject:test-ABC :
# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 centos66.ehowstuff.local ESMTP Postfix
ehlo abc.com
250-centos66.ehowstuff.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:admin@ehowstuff.com
250 2.1.0 Ok
rcpt to:admin@ehowstuff.com
250 2.1.5 Ok
data
354 End data with .
subject:test-ABC
.
250 2.0.0 Ok: queued as 196AD1FDEA
quit
221 2.0.0 Bye
Connection closed by foreign host.
7. Please confirm that the subject “test – ABC” is appearing in the log :
# tail -f /var/log/maillog
Apr  6 23:41:28 centos66 postfix/smtpd[4919]: connect from localhost[::1]
Apr  6 23:41:58 centos66 postfix/smtpd[4919]: 196AD1FDEA: client=localhost[::1]
Apr  6 23:42:07 centos66 postfix/cleanup[4924]: 196AD1FDEA: warning: header subject:test-ABC from localhost[::1]; from= to= proto=ESMTP helo=
Apr  6 23:42:07 centos66 postfix/cleanup[4924]: 196AD1FDEA: message-id=<20150406154158.196AD1FDEA@centos66.ehowstuff.local>
Apr  6 23:42:07 centos66 postfix/qmgr[4914]: 196AD1FDEA: from=, size=365, nrcpt=1 (queue active)
Apr  6 23:42:09 centos66 postfix/smtpd[4919]: disconnect from localhost[::1]

Postfix_logo

How to Perfom SMTP Test Command in Linux

Q. I just installed postfix on my linux virtual private server (VPS), but i am not sure how to verify the SMTP service and perform SMTP test to ensure the email delivery working fine or not ?

A. In Linux, you can send email, peform SMTP test and diagnose email errors through the TELNET linux command :

As an example :

[root@localhost ~]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 localhost.localdomain ESMTP Postfix
helo abc.com
250 localhost.localdomain
mail from:user@scriptsmy.com
250 2.1.0 Ok
rcpt to:ehowstufff@gmail.com
250 2.1.5 Ok
data
354 End data with .
Subject: test Email From Scriptsmy.com
Hi,

This is just test email.

regards,
.
250 2.0.0 Ok: queued as A0E013CC6
quit
221 2.0.0 Bye

Type command 1 to command 7
Command 1 :

[root@localhost ~]# telnet localhost 25

Command 2 :

helo abc.com

Command 3 :

mail from:user@scriptsmy.com

Command 4 :

rcpt to:ehowstufff@gmail.com

Command 5 :

data

Command 6 :

Subject: test Email From Scriptsmy.com
Hi,

This is just test email.

regards,
.

Command 7 :

quit

Check the status in maillog

[root@localhost ~]# tail -f /var/log/maillog
Oct 18 06:01:49 localhost postfix/cleanup[20296]: A0E013CC6: message-id=<20141018060058.A0E013CC6@localhost.localdomain>
Oct 18 06:01:49 localhost postfix/qmgr[20267]: A0E013CC6: from=, size=401, nrcpt=1 (queue active)
Oct 18 06:01:50 localhost postfix/smtp[20318]: A0E013CC6: to=, relay=gmail-smtp-in.l.google.com[2607:f8b0:4003:c05::1a]:25, delay=76, delays=75/0.01/0.12/1.3, dsn=2.0.0, status=sent (250 2.0.0 OK 1413612110 yv8si3312807oeb.10 - gsmtp)
Oct 18 06:01:50 localhost postfix/qmgr[20267]: A0E013CC6: removed
Oct 18 06:01:53 localhost postfix/smtpd[20293]: disconnect from localhost[::1]

How to setup Postfix Transport to Route the email messages

This post will show you how to route messages to other mail server using postfix transport file. This feature allows you to perform mail routing to respective host according to the map defined. Postfix will checking the transport map first instead of reading the DNS for MX record. The steps was tested on CentOS 6.5 and Postfix 2.6.6.

1. In order for Postfix to use the transport file, configure main.cf to use transport map :

vi /etc/postfix/main.cf

Append the following at the bottom :

transport_maps = hash:/etc/postfix/transport

2. Edit transport map file :

vi /etc/postfix/transport

Append the following at the bottom :

ehowstuff.local           smtp:[192.168.0.2]

3. Rebuild the transport database file :

[root@mx-mx06 ~]# postmap /etc/postfix/transport

Note : The command “postmap /etc/postfix/transport” should be execute whenever you change the transport table.

4. Reload postfix to apply the new transport :

[root@mx-mx06 ~]# postfix reload
postfix/postfix-script: refreshing the Postfix mail system

5. Verify :

[root@mx-mx06 ~]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 mx.ehowstuff.local ESMTP Postfix
ehlo abc.com
250-mx.ehowstuff.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:root@ehowstuff.local
250 2.1.0 Ok
rcpt to:root@ehowstuff.local
250 2.1.5 Ok
data
354 End data with .
.
250 2.0.0 Ok: queued as D02D861B50
quit
221 2.0.0 Bye
Connection closed by foreign host.

How to Setup Postfix on CentOS 6.4

Posfix MailPostfix is a open-source mail transfer agent (MTA) that routes and delivers electronic mail. Postfix is an alternative for Sendmail service which provide the same function. This post will describe on how you can install and setup postfix on CentOS 6.4. After you installed postfix, you can use postfix command to controls the operation of the Postfix mail system such as start or stop the master daemon, do a health check, and other maintenance.

1. To install Postfix, use the following yum command :

[root@centos64 ~]# yum install postfix -y

2. To verify if Postfix is already installed, use the following rpm command :

[root@centos64 ~]# rpm -q postfix

Example :

[root@centos64 ~]# rpm -q postfix
postfix-2.6.6-2.2.el6_1.x86_64

3. How to check Postfix version :

[root@centos64 ~]# postconf -d | grep mail_version

Example :

[root@centos64 ~]# postconf -d | grep mail_version
mail_version = 2.6.6
milter_macro_v = $mail_name $mail_version

4. Configure Basic postfix main.cf file :

[root@centos64 ~]# vi /etc/postfix/main.cf

Uncomment and modify the following two line :

myhostname = centos6.4.ehowstuff.local
mydomain = ehowstuff.local

myhostname: is the host name of the system (i.e, the system is called mail or mail.example.com).
mydomain: is the domain name for the email server (it can be a real or fake domain name).

5. Start the postfix service :

[root@centos64 ~]# service postfix start
Starting postfix:                                          [  OK  ]

6. Restart the postfix service :

[root@centos64 ~]# service postfix restart
Shutting down postfix:                                     [  OK  ]
Starting postfix:                                          [  OK  ]

7. How to show postfix pid number on running for postfix services ?

[root@centos64 ~]# ps -ef | grep postfix
root      3081     1  0 05:57 ?        00:00:00 /usr/libexec/postfix/master
postfix   3083  3081  0 05:57 ?        00:00:00 pickup -l -t fifo -u
postfix   3084  3081  0 05:57 ?        00:00:00 qmgr -l -t fifo -u
root      3292  1963  0 06:40 pts/0    00:00:00 grep postfix

How to Remove the Postfix Mail Queue

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers an email. Under Postfix MTA, there are basic command to empty or remove Postfix Mail Queue. In the case of the postfix MTA server suddenly offline or postfix service not respond, all the mail will be in queued. To avoid the messages sent out when it reconnected to the internet, you have an option to empty the mail queue. In this post, i will show how to remove the Postfix Mail Queue using postsuper command.

1. Send an email using telnet command :

[root@centos63 ~]# telnet localhost 25
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 centos63.ehowstuff.local ESMTP Postfix
helo abc.com
250 centos63.ehowstuff.local
mail from:
250 2.1.0 Ok
rcpt to:
250 2.1.5 Ok
data
354 End data with .
subject: Test
.
250 2.0.0 Ok: queued as DB92A1231
quit
221 2.0.0 Bye
Connection closed by foreign host.

2. To see mail queue, enter the following :

[root@centos63 ~]# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
DB92A1231*      359 Tue Feb  5 22:14:01  admin@ehowstuff.com
                                         admin@ehowstuff.com

-- 0 Kbytes in 1 Request.

3. Check mail transaction log :

[root@centos63 ~]# grep DB92A1231 /var/log/maillog
2013-02-05T22:14:14.899894+08:00 centos63 postfix/smtpd[2406]: DB92A1231: client=localhost[::1]
2013-02-05T22:14:23.843262+08:00 centos63 postfix/cleanup[2422]: DB92A1231: message-id=<20130205141414.DB92A1231@centos63.ehowstuff.local>
2013-02-05T22:14:23.946379+08:00 centos63 postfix/qmgr[2197]: DB92A1231: from=, size=359, nrcpt=1 (queue active)
2013-02-05T22:14:55.526423+08:00 centos63 postfix/smtp[2423]: DB92A1231: to=, relay=none, delay=54, delays=22/0.02/32/0, dsn=4.4.1, status=deferred (connect to ehowstuff.com[184.173.214.97]:25: Connection timed out)

4. To remove all mails in the deferred queue, enter the following :

[root@centos63 ~]# postsuper -d ALL deferred
postsuper: Deleted: 1 message

5. To remove all mail from the queue, enter the following :

[root@centos63 ~]# postsuper -d ALL

How to Check Postfix Version

PosfixThis short guides shows how to quickly check your postfix mail server version. Basically, postfix is a open-source mail transfer agent (MTA) that routes and delivers electronic mail. Postfix is an alternative for Sendmail service which provide the same function.

Please execute the following command :

postconf -d | grep mail_version

Examples :

[root@centos62 ~]# postconf -d | grep mail_version
mail_version = 2.6.6
milter_macro_v = $mail_name $mail_version

How to Test Posfix Mail Service using Telnet

PosfixIn order to test the mail services working properly, testing needs to be performed. Instead of using GUI mail client or webmail to test the sending and receiving email,you also can use telnet. Telnet is the most basic mail client. It does the same thing as advanced mail client such as Microsoft Outlook and Mozilla Thunderbird. Telnet will verify and check the server responses to mail requests that was typed.

Perform Testing for Posfix Mail Service using Telnet on linux shell :

[root@mail ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.zimbra.local ESMTP Postfix
Helo mail.zimbra.local
250 mail.zimbra.local
MAIL FROM:<admin@zimbra.local>
250 2.1.0 Ok
RCPT TO:<user@zimbra.local>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: My Test Email
This is the body of the Email
.
250 2.0.0 Ok: queued as 194869C1AB
quit
221 2.0.0 Bye
Connection closed by foreign host.

Perform Testing for Posfix Mail Service using Telnet on Windows Command Prompt :

C:\>telnet mail.zimbra.local 25

220 mail.zimbra.local ESMTP Postfix
ehlo mail.zimbra.local
250-mail.zimbra.local
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
MAIL FROM:<admin@zimbra.local>
250 2.1.0 Ok
RCPT TO:<user@zimbra.local>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: My Test Email
This is the body of the EMAIL Message!
.
250 2.0.0 Ok: queued as 538BB9C1AD

Steps to Perform Testing the Postfix Mail Service

1. Establish a TCP connection to port 25 which is postfix port :

[root@mail ~]# telnet localhost 25

You should receive a 220 response:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 mail.zimbra.local ESMTP Postfix

Postfix is listening and we can communicate with SMTP now.

2. Next,greet the postfix server. The function is considered same with postman or transport :

Helo mail.zimbra.local

The postfix mail server should respond as below :

250 mail.zimbra.local

3. Inform the postfix server know who the sender is:

MAIL FROM:<admin@zimbra.local>

You will get ‘250’ output if the postfix accepts the sender address :

250 2.1.0 Ok

4. Specify the recipient of the email :

RCPT TO:<user@zimbra.local>

If Postfix accepts the recipient address will returned 250 response :

250 2.1.5 Ok

5. Send the actual Email with subject and body of the email :

DATA

Postfix agrees and feedback us to start actual email and returned this output :

354 End data with <CR><LF>.<CR><LF>

6. Start compose the mail, type the word ‘Subject:’ for email subject then enter. Type email body end our input with a dot.

Subject: My Test Email
This is the body of the Email
.

As before, if postfix agress and accepts the email, it will returned 250 response :

250 2.0.0 Ok: queued as 194869C1AB

7. Postfix test fixt telnet finished at the moment, So you can quit :

quit
221 2.0.0 Bye
Connection closed by foreign host.

Trace the mail on Postfix Mail server using message ID :

On Linux shell, message id is 194869C1AB :

[root@mail ~]# cat /var/log/maillog | grep 194869C1AB
Jun  5 01:58:21 mail postfix/smtpd[12285]: 194869C1AB: client=localhost.localdomain[127.0.0.1]
Jun  5 01:59:24 mail postfix/cleanup[17117]: 194869C1AB: message-id=<20120604175821.194869C1AB@mail.zimbra.local>
Jun  5 01:59:24 mail postfix/qmgr[4464]: 194869C1AB: from=<admin@zimbra.local>, size=409, nrcpt=1 (queue active)
Jun  5 01:59:25 mail postfix/cleanup[17117]: 52A7E9C1AD: message-id=<20120604175821.194869C1AB@mail.zimbra.local>
Jun  5 01:59:25 mail postfix/smtp[17317]: 194869C1AB: to=<user@zimbra.local>, relay=127.0.0.1[127.0.0.1]:10024, delay=73, delays=72/0.02/0.1/0.76, dsn=2.0.0, status=sent (250 2.0.0 from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as 52A7E9C1AD)
Jun  5 01:59:25 mail postfix/qmgr[4464]: 194869C1AB: removed

On Windows Command Prompt, the message id is 538BB9C1AD.

[root@mail ~]# cat /var/log/maillog | grep 538BB9C1AD
Jun  5 02:14:08 mail postfix/smtpd[21232]: 538BB9C1AD: client=unknown[192.168.1.52]
Jun  5 02:14:55 mail postfix/cleanup[22300]: 538BB9C1AD: message-id=<20120604181408.538BB9C1AD@mail.zimbra.local>
Jun  5 02:14:55 mail postfix/qmgr[4464]: 538BB9C1AD: from=<admin@zimbra.local>, size=408, nrcpt=1 (queue active)
Jun  5 02:15:05 mail postfix/cleanup[22300]: EDD0E9C1AE: message-id=<20120604181408.538BB9C1AD@mail.zimbra.local>
Jun  5 02:15:05 mail postfix/smtp[22317]: 538BB9C1AD: to=<user@zimbra.local>, relay=127.0.0.1[127.0.0.1]:10024, delay=74, delays=65/0.02/1.6/7.8, dsn=2.0.0, status=sent (250 2.0.0 from MTA([127.0.0.1]:10025): 250 2.0.0 Ok: queued as EDD0E9C1AE)
Jun  5 02:15:05 mail postfix/qmgr[4464]: 538BB9C1AD: removed