Blog >> Linux >> Whitepapers.
Postfix 를 기반으로 한 MTA 구축
포털 smtp 를 이용한 메일 발송용 MTA 를 설정해 본다.
# main.cf
# ==========================================
# Server Local Reporting -> Daum SMTP Relay
# ==========================================
inet_interfaces = loopback-only
mynetworks_style = host
mynetworks = 127.0.0.0/8 [::1]/128
# Daum SMTP Relay (Port 465 SSL)
relayhost = [smtp.daum.net]:465
# 포트 465 전용 Wrapper 모드 동작 (smtp_tls_wrappermode = yes)
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
smtp_tls_mandatory_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
smtp_tls_protocols = !SSLv2, !SSLv3, !TLSv1, !TLSv1.1
# SASL Authentication
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = lmdb:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
# Restrictions
smtpd_sender_restrictions = permit_mynetworks, reject
smtpd_relay_restrictions = permit_mynetworks, rejectsmtpd_sasl_auth_enable = yes 제거 권장. smtp_sasl_auth_enable 아니고, smtpd 제거.
smtpd_…는 “내 Postfix 서버에 누군가 접속해서 메일을 보낼 때 인증을 요구할 지” 를 정하는 옵션.
외부 접속을 받지 않고 로컬 시스템에서만 메일을 보내므로, 로컬 데몬이 로그인 없이 바로 메일을 던질 수 있게 smtpd_sasl_auth_enable = no로 두거나 삭제하는 것이 맞다. 필요한 것은 외부 Daum으로 나갈 때 인증하는 smtp_sasl_auth_enable = yes이다.
postconf relayhost smtp_sasl_auth_enable 실행 시 각각 [smtp.daum.net]:465 와 yes가 정상 출력되는지 확인.
# /etc/postfix/sasl_passwd 단일 등록:
[smtp.daum.net]:465 접속계정명:다음메일앱비밀번호
# LMDB 생성
chmod 600 /etc/postfix/sasl_passwd
postmap lmdb:/etc/postfix/sasl_passwd# /etc/postfix/main.cf에 1줄 추가:
smtp_generic_maps = lmdb:/etc/postfix/generic
# root@localhost 등으로 나가는 메일이 외부에서 스팸 처리되지 않도록
# /etc/postfix/generic 또는 canonical에 root -> p****@****.co.kr 매핑
# /etc/postfix/generic
root@mail.local phobe@gldigital.co.kr
root@localhost phobe@gldigital.co.kr
root phobe@gldigital.co.kr
phobe@mail.local phobe@gldigital.co.kr
# LMDB 생성
postmap lmdb:/etc/postfix/generic# /etc/aliases 파일 맨 아래 확인/추가:
root: phobe@gldigital.co.kr, phobezzang@gmail.com
# 변경 사항 적용 (DB 갱신):
newaliases# 문법 에러 체크 (아무 메시지도 출력되지 않아야 정상)
postfix check
# postfix 재시작
systemctl restart postfix
systemctl status postfix향후 Gmail / 샌드박스(Amazon SES, Mailgun 등) 전환 시 변경 포인트 딱 두 부분만 수정
# Gmail SMTP 사용 시:
relayhost = [smtp.gmail.com]:587
# Gmail 포트 587은 Wrapper 모드가 아닌 STARTTLS 방식이므로
smtp_tls_wrappermode = no
smtp_tls_security_level = encrypt적용은 Daum SMTP – 카카오 메일과 아주 혼동하기 쉽다. 기준은 다음 스마트워크.
다음의 안내에는 “아웃룩(IMAP/POP3)과 같이 2단계 인증을 지원하지 않는 서비스에서는 앱 비밀번호를 이용해 Kakao 메일에 로그인할 수 있습니다.” – 앱 비밀번호가 필요하다. 그리고 워드프레스 설정.
# 테마 펑션 파일에
/* ============================================================
Daum SMTP 연결
true: Daum SMTP 직접 연결
false: 로컬 시스템 메일러(기존 Postfix 등)
============================================================ */
define('USE_CUSTOM_SMTP', true);
if (defined('USE_CUSTOM_SMTP') && USE_CUSTOM_SMTP) {
$smtp_file = get_stylesheet_directory() . '/includes/smtp.php';
if (file_exists($smtp_file)) {
require_once $smtp_file;
}
}# 테마폴더/includes/smtp.php
<?php
/**
* Daum SMTP Relay Module via PHPMailer.
*/
if (!defined('ABSPATH')) {
exit;
}
add_action('phpmailer_init', function ($phpmailer) {
$phpmailer->isSMTP();
$phpmailer->Host = 'smtp.daum.net';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 465;
$phpmailer->Username = 'ph****';
$phpmailer->Password = defined('DAUM_SMTP_PASS') ? DAUM_SMTP_PASS : '';
$phpmailer->SMTPSecure = 'ssl';
// 발송자 기본값 고정
$phpmailer->From = p****@****.co.kr';
$phpmailer->FromName = get_bloginfo('name');
});# wp-config.php - DAUM_SMTP_PASS 지정 앱 비밀번호 분리
define('DAUM_SMTP_PASS', '*****');# 쉘에서 메일테스트
# 에러 없이 bool(true)가 출력되면 ph****@****.com 메일함에 정상 도착함.
php -r "require 'wp-load.php'; add_action('wp_mail_failed', function(\$e){ echo 'ERROR: ' . \$e->get_error_message() . PHP_EOL; }); var_dump(wp_mail('ph****@****.com', '스마트워크 최종 테스트', '아이디 수정 후 발송 테스트'));"폼 플러그인(Formidable 등) 설정 시 딱 한 가지만 주의할 점
폼 설정에서 보내는 사람 이메일(From Email) 항목만 확인 후 다음 스마트워크에 등록된 본인 이메일(예: p****@****.co.kr 또는 Username에 쓴 메일)로 지정
메일 발송 시 보내는 이름이 Super User 로 표기 될 때. 시스템에 정해진 – /etc/passwd – 이름으로 가기 때문.
그래서 보내는 Super User 를 치환.
passwd 파일을 텍스트 편집기(vi, nano 등)로 직접 수정하는 것은 기술적으로 가능하지만, 치명적인 시스템 장애 위험이 있어 권장하지 않는다.
1. 문법 오류 시 root 로그인 불가 (시스템 잠김)
2. 동시 접근 충돌 (File Locking 부재)
3. SELinux 컨텍스트 손상 위험
텍스트 편집기로 직접 보고 고치는 방식을 선호하신다면 일반 편집기 대신 반드시 vipw 명령어를 사용
chfn -f "GL204 OPS Team" root
grep '^root:' /etc/passwd


