• 메일 발송에 문제가 있다고하여 찾아보고 테스트했던 기록 (Update: Aug 21, 2021)

실행 환경

OS: CentOS 7
Service: Postfix v2.10.1

1. 서버, 서비스 점검

[USER1@MailServer01 ~]$ df -h |grep -v tmpfs
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda2       279G  2.9G  262G   2% /
/dev/sda1       477M  128M  320M  29% /boot

[USER1@MailServer01 ~]$ systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running)
   (...생략...)

[USER1@MailServer01 ~]$ postfix status
postfix/postfix-script: the Postfix mail system is running: PID: 1706

[USER1@MailServer01 ~]$ netstat -napt |grep :25
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      1706/master
tcp        0      1 192.168.100.213:59928       192.168.49.5:25             SYN_SENT    1824/smtp
tcp        0      0 192.168.100.213:44582       192.168.238.100:25          TIME_WAIT   -
tcp        0      0 192.168.100.213:33406       192.168.108.46:25           ESTABLISHED 1730/smtp
tcp        0      0 192.168.100.213:53068       192.168.157.27:25           ESTABLISHED 1729/smtp

[USER1@MailServer01 ~]$ netstat -napt |grep SYN_SENT
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      1 192.168.100.213:60338       192.168.92.148:25           SYN_SENT    1328/smtp
tcp        0      1 192.168.100.213:56134       128.14.151.197:25           SYN_SENT    1814/smtp
tcp        0      1 192.168.100.213:57334       192.168.222.142:25          SYN_SENT    1700/smtp
tcp        0      1 192.168.100.213:47934       192.168.159.23:25           SYN_SENT    1705/smtp
tcp        0      1 192.168.100.213:57336       192.168.222.142:25          SYN_SENT    1726/smtp
tcp        0      1 192.168.100.213:57344       192.168.222.142:25          SYN_SENT    1816/smtp

[USER1@MailServer01 ~]$ mailq
Mail queue is empty

[USER1@MailServer01 ~]$ postqueue -p
Mail queue is empty

[USER1@MailServer01 ~]$ ls -altR /var/spool/postfix/defer |grep -Ev '^d|^s' |grep 'Aug 18'|wc -l
363
[USER1@MailServer01 ~]$ ls -altR /var/spool/postfix/deferred/ |grep -Ev '^d|^s' |grep 'Aug 18'|wc -l
363
[USER1@MailServer01 ~]$ ls -altR /var/spool/postfix/hold/ |grep -Ev '^d|^s' |grep 'Aug 18'|wc -l
0
[USER1@MailServer01 ~]$ ls -altR /var/spool/postfix/incoming/ |grep -Ev '^d|^s' |grep 'Aug 18'|wc -l
0
[USER1@MailServer01 ~]$ ls -altR /var/spool/postfix/active/ |grep -Ev '^d|^s' |grep 'Aug 18'|wc -l
0

; 참고

$ postqueue -f
$ postfix flush
# you can force Postfix to immediately attempt to send all queued messages. There are two to choose from:

$ postsuper -d ALL			    #메일 큐 전체 삭제
$ postsuper -d ALL deferred	    #메일 큐에서 deferred 상태인 메일만 삭제
# allow you to delete all queued messages in Postfix. This includes messages from both the pending and deferred queues:

2. 메일 발송 테스트

2-1. 다른 서버에서 telnet으로 발송

[USER1@WEB01 ~]$ telnet MAIL.BRANCH_OFFICE.TEST.COM 25
Trying 192.168.100.119...
Connected to MAIL.BRANCH_OFFICE.TEST.COM.
Escape character is '^]'.
220 MailServer01.BRANCH_OFFICE.TEST.COM ESMTP Postfix
ehlo 127.0.0.1
250-MailServer01.BRANCH_OFFICE.TEST.COM
250-PIPELINING
250-SIZE 20480000
250-VRFY
250-ETRN
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:reporter11@BRANCH_OFFICE.TEST.COM
250 2.1.0 Ok
rcpt to:head01@HO.TEST.COM
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test mail from WEB01, 10:07
.
250 2.0.0 Ok: queued as A547A1000487
subject:testmail2
221 2.7.0 Error: I can break rules, too. Goodbye.
Connection closed by foreign host.

; 메일 발송 성공 로그

Aug 19 10:06:57 MailServer01 postfix/smtpd[21119]: connect from WEB01.BRANCH_OFFICE.TEST.COM[192.168.100.217]
Aug 19 10:07:24 MailServer01 postfix/smtpd[21119]: A547A1000487: client=WEB01.BRANCH_OFFICE.TEST.COM[192.168.100.217]
Aug 19 10:07:59 MailServer01 postfix/cleanup[21702]: A547A1000487: message-id=<>
Aug 19 10:07:59 MailServer01 postfix/qmgr[39584]: A547A1000487: from=<reporter11@BRANCH_OFFICE.TEST.COM>, size=264, nrcpt=1 (queue active)
Aug 19 10:08:01 MailServer01 postfix/smtp[22012]: A547A1000487: to=<head01@HO.TEST.COM>, relay=mx2.ho1234-12.TEST.COM[192.168.100.183]:25, delay=42, delays=41/0.02/0.55/0.77, dsn=2.0.0, status=sent (250 ok: Message 777213156 accepted)
Aug 19 10:08:01 MailServer01 postfix/qmgr[39584]: A547A1000487: removed
Aug 19 10:08:16 MailServer01 postfix/smtpd[21119]: warning: non-SMTP command from WEB01.BRANCH_OFFICE.TEST.COM[192.168.100.217]: subject:testmail2

2-2. 메일 서버에서 mail로 발송

[USER1@MailServer01 ~]$ sudo yum install mailx

[USER1@MailServer01 ~]$ date | mailx -s "service check" -r reporter11@BRANCH_OFFICE.TEST.COM head01@HO.TEST.COM

[USER1@MailServer01 ~]$ date | mail -s "service check" -r reporter11@BRANCH_OFFICE.TEST.COM head01@HO.TEST.COM

; 메일 발송 성공 로그

[USER1@MailServer01 ~]$ grep reporter11 /var/log/maillog
Aug 17 22:53:23 MailServer01 postfix/smtp[28251]: 4BABB6A1E40: to=<reporter11@naver.com>, relay=mx2.NAVER.COM[125.209.238.137]:25, delay=0.86, delays=0.02/0.3/0.02/0.52, dsn=2.0.0, status=sent (250 2.0.0 OK OOX9VjeBRXGN5u0zqV4O5g - nsmtp)
Aug 18 17:44:41 MailServer01 postfix/pickup[39583]: D61301000738: uid=0 from=<reporter11@BRANCH_OFFICE.TEST.COM>
Aug 18 17:44:41 MailServer01 postfix/cleanup[44236]: D61301000738: message-id=<611cc879.VWX9VvpHQka4657H%reporter11@BRANCH_OFFICE.TEST.COM>
Aug 18 17:44:41 MailServer01 postfix/qmgr[39584]: D61301000738: from=<reporter11@BRANCH_OFFICE.TEST.COM>, size=471, nrcpt=1 (queue active)
Aug 18 17:44:43 MailServer01 postfix/smtp[44238]: D61301000738: to=<head01@HO.TEST.COM>, relay=mx2.ho1234-12.TEST.COM[192.168.100.207]:25, delay=1.2, delays=0.01/0/0.42/0.8, dsn=2.0.0, status=sent (250 ok:  Message 771430293 accepted)
Aug 18 17:44:43 MailServer01 postfix/qmgr[39584]: D61301000738: removed

; 메일 발송 실패

[USER1@MailServer01 ~]$ grep head01 /var/log/maillog
Aug 18 12:06:46 MailServer01 postfix/smtp[6699]: BB8911000700: to=<head01@HO.TEST.COM>, relay=mx1.ho0987-12.TEST.COM[192.168.100.128]:25, delay=1.9, delays=0.04/0.02/1.7/0.15, dsn=5.0.0, status=bounced (host mx1.ho0987-12.TEST.COM[192.168.100.128] said: 501 5.5.2 syntax error 'MAIL FROM:<USER1@MailServer01.BRANCH_OFFICE.TEST.COM> SIZE=507' (in reply to MAIL FROM command))

3. 발송 실패 확인

3-1. 방화벽 등으로 메일 서버로 접근이 안될 경우

connect to gmail-smtp-in.l.google.com[2404:6800:4008:c00::1b]:25: Network is unreachable

Aug 18 16:50:10 MailServer01 postfix/pickup[29294]: 563661000738: uid=2140601791 from=<reporter11...
Aug 18 16:50:10 MailServer01 postfix/cleanup[38190]: 563661000738: message-id=<20200818075010.563661000738@MailServer01.BRANCH_OFFICE.TEST.COM>
Aug 18 16:50:10 MailServer01 postfix/qmgr[7631]: 563661000738: from=<reporter11@MailServer01.BRANCH_OFFICE.TEST.COM>, size=522, nrcpt=1 (queue active)
Aug 18 16:50:11 MailServer01 postfix/smtp[38192]: connect to gmail-smtp-in.l.google.com[2404:6800:4008:c00::1b]:25: Network is unreachable
Aug 18 16:50:11 MailServer01 postfix/smtp[38192]: 563661000738: to=<reporter11@gmail.com>, relay=gmail-smtp-in.l.google.com[108.177.97.26]:25, delay=1.6, delays=0.01/0/1.4/0.18, dsn=5.1.7, status=bounced (host gmail-smtp-in.l.google.com[108.177.97.26] said: 553-5.1.7 The sender address <reporter11@MailServer01.BRANCH_OFFICE.TEST.COM> is 553 5.1.7 not a valid RFC-5321 address. c18si5885039pgc.294 - gsmtp (in reply to MAIL FROM command))
Aug 18 16:50:12 MailServer01 postfix/bounce[38193]: 563661000738: sender non-delivery notification: 23475100073

3-2. 메일 주소에 오류가 있거나 임의 작성할 경우

said: 553 #5.1.8 Domain of sender address report11@WOWWOW.IO does not exist (in reply to MAIL FROM command))

said: 553-5.1.7 The sender address <reporter11@MailServer01.BRANCH_OFFICE.TEST.COM> is 553 5.1.7 not a valid RFC-5321 address. d14si5879612plh.24 - gsmtp (in reply to MAIL FROM command))

Aug 18 17:55:12 MailServer01 postfix/pickup[39583]: 885771000738: uid=0 from=<report11@WOWWOW.IO>
Aug 18 17:55:12 MailServer01 postfix/cleanup[45530]: 885771000738: message-id=<611ccaf0.PE8svUx0zZ2OJSIn%report11@WOWWOW.IO>
Aug 18 17:55:12 MailServer01 postfix/qmgr[39584]: 885771000738: from=<report11@WOWWOW.IO>, size=445, nrcpt=1 (queue active)
Aug 18 17:55:13 MailServer01 postfix/smtp[45532]: 885771000738: to=<head01@HO.TEST.COM>, relay=mx1.ho0987-12.TEST.COM[192.168.100.44]:25, delay=0.64, delays=0.01/0/0.46/0.18, dsn=5.0.0, status=bounced (host mx1.ho0987-12.TEST.COM[192.168.100.44] said: 553 #5.1.8 Domain of sender address report11@WOWWOW.IO does not exist (in reply to MAIL FROM command))
Aug 18 17:55:13 MailServer01 postfix/bounce[45656]: 885771000738: sender non-delivery notification: 54CA7100073A

3-3. syntax error

; 도메인 주소에 whitespace 또는 _가 있는 경우에도 보게 되는 오류

status=bounced (host mx1.ho0987-12.TEST.COM[192.168.100.88] said: 501 #5.5.2 syntax error ‘MAIL …

Aug 18 15:29:39 MailServer01 postfix/smtp[29219]: 48727100071D: to=<head01@HO.TEST.COM>, relay=mx1.ho0987-12.TEST.COM[192.168.100.88]:25, delay=0.69, delays=0.02/0/0.52/0.14, dsn=5.0.0, status=bounced (host mx1.ho0987-12.TEST.COM[192.168.100.88] said: 501 #5.5.2 syntax error 'MAIL FROM:<USER1@MailServer01.BRANCH_OFFICE.TEST.COM> SIZE=507' (in reply to MAIL FROM command))

4. 참고 사항

4-1. 메일 서버 추가 체크사항

; 도메인에 join된 메일서버거나 도메인 연결이 안될 경우 추가로 확인

[USER1@MailServer01 ~]$ hostname -d
BRANCH_OFFICE.TEST.COM

[USER1@MailServer01 ~]$ hostname -s
MailServer01

[USER1@MailServer01 ~]$ hostname -f
MailServer01.BRANCH_OFFICE.TEST.COM

[USER1@MailServer01 ~]$ cat /etc/hostname 
MailServer01.BRANCH_OFFICE.TEST.COM

[USER1@MailServer01 ~]$ cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
127.0.0.1   MailServer01.BRANCH_OFFICE.TEST.COM MailServer01

4-2. 메일 큐 디렉토리

  • /var/spool/postfix/hold
    관리자 개입 때까지 무기한 보류. “postsuper -r"로 보류 해제, maildrop 대기열로 이동시킨다.
  • /var/spool/postfix/incoming
    Postfix 대기열로 들어오는 새 메일은 “incoming” 대기열에 기록된다. 정상적인 상태에서는 mode 0600 files 존재하고 거의 비워져 있다.
  • /var/spool/postfix/deferred
    메일 발송 후 (발송이 가능한) 실패된 메일들이 배치된다.
  • /var/spool/postfix/active
    incoming queue 수신과 & deferred queue 재시도로 발생한다.
  • /var/spool/postfix/corrupt
  • /var/spool/postfix/maildrop

참고 글