본문 바로가기

리눅스

[draft] 우분투에서 Postfix와 Dovecot을 구축하고 설정하는 방법

우분투에서 Postfix와 Dovecot을 구축하고 설정하는 방법

1. 패키지 설치

sudo apt update
sudo apt install -y mailutils
sudo apt install -y postfix dovecot-core dovecot-imapd dovecot-pop3d

postfix : 메일 송신 서버 (MTA)

dovecot-core : Dovecot 기본 서비스

dovecot-imapd, dovecot-pop3d : IMAP, POP3 지원

mailutils : 테스트용 메일 전송 도구

 

설치 중 Postfix configuration 창이 뜨면

Postfix configuration

  • Internet Site 선택

Postfix configuration

  • mail.example.com 과 같은 호스트 이름 입력

Postfix 재구성

dpkg-reconfigure postfix

2. Postfix 기본 설정

Postfix 구성 파일을 수정합니다.

vim /etc/postfix/main.cf
# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 3.6 on
# fresh installs.
compatibility_level = 3.6



# 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

smtp_tls_CApath=/etc/ssl/certs
smtp_tls_security_level=may
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache


smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = pmail.vm.sangchul.kr
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = /etc/mailname
mydestination = $myhostname, pmail.vm.sangchul.kr, localhost, localhost.localdomain, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = all

Maildir 형식으로 메일 저장

mkdir -p ~/Maildir/{cur,new,tmp}
chmod -R 700 ~/Maildir

변경 후 Postfix 재시작

sudo systemctl restart postfix
sudo systemctl enable postfix

3. Dovecot 구성

Dovecot 구성 파일을 수정합니다.

vim /etc/dovecot/dovecot.conf
# protocols: 사용할 프로토콜 설정
protocols = imap pop3

# mail_location: 메일 저장 위치 설정
mail_location = maildir:~/Maildir

# ssl_cert: SSL 인증서 경로 설정
ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key

# auth_username_format: 사용자 이름 형식 설정
auth_username_format = %n

# auth_mechanisms: 인증 메커니즘 설정
auth_mechanisms = plain login

4. 가상 도메인 및 사용자 설정

가상 도메인 매핑 파일을 생성합니다.

vim /etc/postfix/virtual
pmail.vm.sangchul.kr     user1@pmail.vm.sangchul.kr
pmail.vm.sangchul.kr     user2@pmail.vm.sangchul.kr

5. 서비스 재시작

Postfix와 Dovecot 서비스를 재시작합니다.

sudo systemctl restart postfix
sudo systemctl restart dovecot

6. 동작 확인

Postfix 메일 송신 테스트

echo "Test Mail from Postfix" | mail -s "Postfix Test" user@example.com

Dovecot 메일 수신 테스트

telnet localhost 143   # IMAP 연결 확인
telnet localhost 110   # POP3 연결 확인

 

Postfix와 Dovecot의 구성 및 설정이 완료되었습니다. 이제 메일 서버가 작동하고 있으며, 이메일 클라이언트를 사용하여 메일을 송수신할 수 있습니다. 필요에 따라 추가적인 구성 및 보안 설정을 수행할 수 있습니다.