postfix 설치 전에 가능하면 postfix에 사용할 인증서는 구하는 것을 추천한다.
설치 후, 설정 파일을 수정하는 부분이 있는 이 부분에 인증서를 넣는 부분이 있다.

무료로 사용할 수 있는 "Let’s Encrypt 인증서"를 기반으로 설명한다.

 

1. 서비스 기반 구성

   o. DNS의 MX 설정  

MacPro:~ $ dig encicle.com mx

; <<>> DiG 9.10.6 <<>> encicle.com mx
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 1724
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;encicle.com.			IN	MX

;; ANSWER SECTION:
encicle.com.		300	IN	MX	10 mail.encicle.com.

;; Query time: 7 msec
;; SERVER: 203.248.252.2#53(203.248.252.2)
;; WHEN: Wed Nov 17 10:45:31 KST 2021
;; MSG SIZE  rcvd: 61

 

    o. SPF 설정

MacPro:~$ dig encicle.com txt

; <<>> DiG 9.10.6 <<>> encicle.com txt
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 16937
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;encicle.com.			IN	TXT

;; ANSWER SECTION:
encicle.com.		300	IN	TXT	"v=spf1 mx mx:mail.encicle.com -all"

;; Query time: 9 msec
;; SERVER: 203.248.252.2#53(203.248.252.2)
;; WHEN: Wed Nov 17 10:46:47 KST 2021
;; MSG SIZE  rcvd: 87

 

    o. PTR 설정

MacPro:~$ dig -x 52.145.33.173

; <<>> DiG 9.10.6 <<>> -x 52.145.33.173
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 48436
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;171.30.141.52.in-addr.arpa.	IN	PTR

;; ANSWER SECTION:
171.30.141.52.in-addr.arpa. 10	IN	PTR	mail.encicle.com.

;; Query time: 40 msec
;; SERVER: 203.248.252.2#53(203.248.252.2)
;; WHEN: Wed Nov 17 10:48:31 KST 2021
;; MSG SIZE  rcvd: 82

위 3가지는 이메일 설정을 위한 가장 기본적인 설정이다.

가능하면 해두자.

 

2. postfix 설치

o. postfix package 설치

$ sudo apt install postfix

    "Internet Site"를 선택해서 외부로 메일 수신/발신 가능하도록 선택 

    이메일에 사용할 도메인 설정

o. ssl 인증서 설정
        - Let’s Encrypt 인증서 Cert : /etc/ssl/conf/fullchain.pem
        - Let’s Encrypt 인증서 Key : /etc/ssl/conf/privkey.pem

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_tls_security_level=may

to

# TLS parameters
smtpd_tls_cert_file=/etc/ssl/conf/fullchain.pem
smtpd_tls_key_file=/etc/ssl/conf/privkey.pem
smtpd_tls_security_level=may

 

3. 구성 검증

ubuntu에 package로 설치하면 기본적으로 STARTTLS 기능이 활성화되어 있다.

telnet 명령어를 통해서 검증

telnet 명령어로 검증하는 방법은 아래와 같다. telnet 명령어를 사용하면 STARTTLS 기능으로 메일을 보낼 수 없다.
(STARTTLS을 사용해서 메일을 보내려면 openssl 명령어를 사용하면된다.)

# telnet localhost 25
EHLO mail.encicle.com 

실행화면은 아래와 같다.

# telnet localhost 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 testmachine ESMTP Postfix (Ubuntu)
EHLO mail.encicle.com
250-testmachine
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING

위와 같이 250-STARTTLS 기능이 활성화된 것을 알 수 있다.

해당 상태에서 메일 전송을 테스트해본다.

아래 명령어를 차례대로 입력해준다.

telnet localhost 25
EHLO mail.encicle.com
mail from: [email protected]
rcpt to: [email protected]
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: test


This is test mail.
.

실행화면은 아래와 같다.

# telnet 127.0.0.1 25
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
220 testmachine ESMTP Postfix (Ubuntu)
EHLO mail.encicle.com
250-testmachine
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
mail from: [email protected]
250 2.1.0 Ok
rcpt to: [email protected]
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subject: test


This is test mail.
.
250 2.0.0 Ok: queued as 749155C1B

당연히 로그(/var/log/syslog 또는 /va/log/mail.log)를 보면 막힌다.

2025-10-21T14:36:56.812952+09:00 testmachine postfix/smtpd[18012]: connect from localhost[127.0.0.1]
2025-10-21T14:37:08.477816+09:00 testmachine postfix/smtpd[18012]: 749155C1B: client=localhost[127.0.0.1]
2025-10-21T14:37:24.443413+09:00 testmachine postfix/cleanup[18328]: 749155C1B: message-id=<20251021053708.749155C1B@testmachine>
2025-10-21T14:37:24.449299+09:00 testmachine postfix/qmgr[18007]: 749155C1B: from=<[email protected]>, size=337, nrcpt=1 (queue active)
2025-10-21T14:37:24.837526+09:00 testmachine postfix/smtp[18333]: 749155C1B: to=<[email protected]>, relay=mx1.naver.com[125.209.238.100]:25, delay=19, delays=19/0.01/0.09/0.27, dsn=5.7.2, status=bounced (host mx1.naver.com[125.209.238.100] said: 550 5.7.2 Your email has been blocked because the sender is unauthenticated. For more information, go to https://help.naver.com/alias/mail/newmail10.naver CmS9i1LrS+G73Hx-xGpKmg - nsmtp (in reply to end of DATA command))
2025-10-21T14:37:24.839772+09:00 testmachine postfix/cleanup[18328]: CC96A5C1F: message-id=<20251021053724.CC96A5C1F@homemachine>
2025-10-21T14:37:24.844862+09:00 testmachine postfix/bounce[18334]: 749155C1B: sender non-delivery notification: CC96A5C1F
2025-10-21T14:37:24.845138+09:00 testmachine postfix/qmgr[18007]: CC96A5C1F: from=<>, size=2608, nrcpt=1 (queue active)
2025-10-21T14:37:24.845318+09:00 testmachine postfix/qmgr[18007]: 749155C1B: removed
2025-10-21T14:37:24.870867+09:00 testmachine postfix/local[18335]: CC96A5C1F: to=<[email protected]>, relay=local, delay=0.03, delays=0.01/0.01/0/0.02, dsn=2.0.0, status=sent (delivered to mailbox)
2025-10-21T14:37:24.871119+09:00 testmachine postfix/qmgr[18007]: CC96A5C1F: removed

요즘에는 많은 이메일 시스템들이 DKIM과 SPF를 요구하고 있어서 차단되었다.

openssl 명령어를 통해서 검증 with 인증서 검증

STARTTLS 기능을 사용해서 통신하는 방법은 아래 명령어를 사용하면 된다.

# openssl s_client -debug -starttls smtp -crlf -connect localhost:25

위와 같이 접속하면 인증서 정보도 자세하게 나온다.

# openssl s_client -debug -starttls smtp -crlf -connect localhost:25
CONNECTED(00000003)
...
---
Certificate chain
 0 s:CN = *.encicle.com
   i:C = US, O = Let's Encrypt, CN = E7
   a:PKEY: id-ecPublicKey, 256 (bit); sigalg: ecdsa-with-SHA384
   v:NotBefore: Aug 31 14:01:47 2024 GMT; NotAfter: Nov 29 14:01:46 2025 GMT
 1 s:C = US, O = Let's Encrypt, CN = E7
   i:C = US, O = Internet Security Research Group, CN = ISRG Root X1
   a:PKEY: id-ecPublicKey, 384 (bit); sigalg: RSA-SHA256
   v:NotBefore: Mar 13 00:00:00 2024 GMT; NotAfter: Mar 12 23:59:59 2027 GMT
---
Server certificate
-----BEGIN CERTIFICATE-----
...

메일을 보내기 위해서는 telnet에 사용한 명령어를 그대로 실행하면 메일을 전송할 수 있다.