본문 바로가기
SW Developer

우분투 Ubuntu 서버 SSMTP로 다우오피스 메일 보내기 방법 및 디버깅

by ashespia 2020. 7. 3.
SMALL

회사 Groupware를 기존 업체에서 Dauoffice.com으로 교체 하였습니다.

그래서 잘 사용하던 mail 발송 관련 된 설정들을 전부 바꾸어야 했습니다.

 

Ubuntu에서 메일 발송을 위한 SSMTP 설치

Ubuntu에서 메일 발송을 위해서는 mailutil 과 ssmtp를 설치해 주어야 합니다.

 

sudo apt-get install mailutil ssmtp

 

 

Ubuntu에서 메일 발송을 위한 SSMTP 설정

ssmtp를 설치하였다면 관련 설정을 해주어야 합니다.

설정 파일의 위치는 /etc/ssmtp/ssmtp.conf​ 에 있습니다.

 

vi /etc/ssmtp/ssmtp.conf​

 

 

다우오피스의 정보에 있는 SMTP 설정들을 세팅해 주어야 합니다.

저희는 SMTP 포트를 465번을 사용하여 mailhub에 해당 값 뒤에 포트 번호를 넣어 주었습니다.

AuthUser는 사용할 이메일 주소를 설정해주시면 됩니다.

AuthPass는 해당 메일 계정의 비밀 번호를 설정해 줍니다.

UseTLS는 Yes로 설정해주어야 저희는 메일이 정상적으로 발송됨을 확인하였습니다.

디버깅 방법은 아래 다시 설명하도록 하겠습니다.

 

rewriteDomain은 다우 오피스 주소를 입력합니다.

 

hostname 도 다우 오피스 주소를 입력해 주었습니다.

 

FromLineOverride는 yes로 설정하였습니다.

#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
#root=postmaster
root=redmine@XXXXX.co.kr

# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
#mailhub=mail
mailhub=outbound.daouoffice.com:465
AuthUser=redmine@XXXXX.co.kr
AuthPass=XXXXXX
UseTLS=YES
#UseSTARTTLS=YES
#AuthMethod=LOGIN

# Where will the mail seem to come from?
rewriteDomain=outbound.daouoffice.com

# The full hostname
hostname=outbound.daouoffice.com

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES

 

 

메일 발송 테스트 방법

 

이제 모든 설정이 완료 되었으면 메일을 발송해서 테스트를 해 봅니다.

 

echo 부분에는 본문 내용

mail -s 옵션 뒤에는 메일 제목

마지막은 수신할 메일 주소를 입력합니다.

 

​echo "test" | mail -s "Test Subject" test@test.co.kr

 

여러 명에서 메일을 보내겠다고 하면 수신자를 늘리면 됩니다.

"," 문자를 통해 이어서 수신인을 늘려주면 되니다.

예를 들어 A,B,C 세명에게 보낸다고 가정하면 아래와 같은 형태로 발송하면 됩니다.

 

​echo "test" | mail -s "Test Subject" test@test.co.kr,A@test.co.kr,B@test.co.kr,C@test.co.kr

 

메일 발신 디버깅 방법

 

SMTP 설정하고 발송한 메일이 잘 발송되었는지 분석을 위한 디버깅 로그는 /var/log/mail.log에서 확인 할 수 있습니다.

 

Jul  3 17:05:26 ubuntu sSMTP[13113]: Creating SSL connection to host
Jul  3 17:05:26 ubuntu sSMTP[13113]: SSL connection using RSA_AES_128_CBC_SHA1
Jul  3 17:05:28 ubuntu sSMTP[13113]: Sent mail for root@outbound.daouoffice.com (221 2.0.0 sendmail3.daouoffice.com Service closing transmission channel) uid=0 username=root outbytes=560

 

디버깅을 위한 방화벽 확인

 

만약 방화벽등의 다른 문제가 있다면 분석을 위해서 tcpdump를 통해 확인 해 볼 수 있습니다.

 

tcpdump 옵션

-i 인터페이스 설정 예제에는 eth1

-w 저장할 tcpdump 파일 마지막에 확장자를 pcap으로 해야 정상동작 

 

tcpdump -i eth1 -w 75_mail_relate_firewall.pcap

 

tcpdump 뜬 파일을 가지고와서 wirshark로 사용하는 프로토콜 및 포트 정보를 확인할 수 있습니다.

만약 해당 포트가 막혀있다면 메일일 정상적으로 발송이 되지 않습니다.

해당 포트를 확인해서 방화벽에 추가해주면 됩니다.

 

LIST

댓글