JJC's 테크니컬 다이어리

Debian9 에서 mail 명령어 메일 활용 하기 본문

Linux

Debian9 에서 mail 명령어 메일 활용 하기

털털한JJC 2018. 7. 18. 14:41

1. ssmtp 설치 및 설정한다.

ssmtp 란 로컬 컴퓨터에서 설정된 메일호스트로 메일을 전달해주는 프로그램으로

구글메일 등을 이용하여 서버에서 메일을 인터넷으로 보낼 수 있습니다.


1.1 ssmtp 설치하기

ubuntu나 debian 에서는 아래와 같이 설치가능

# apt-get install ssmtp -y


1.2 ssmtp설정하기 (구글메일을 이용한 설정샘플)

/etc/ssmtp/ssmtp.conf

# The user that gets all the mails (UID < 1000, usually the admin)
root=username@gmail.com

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
# See also https://support.google.com/mail/answer/78799
mailhub=smtp.gmail.com:587

# The address where the mail appears to come from for user authentication.
rewriteDomain=gmail.com

# The full hostname.  Must be correctly formed, fully qualified domain name or GMail will reject connection.
hostname=yourlocalhost.yourlocaldomain.tld

# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes

# Username/Password
AuthUser=username
AuthPass=password
AuthMethod=LOGIN

# Email 'From header's can override the default domain?
FromLineOverride=yes

※ 상세사항은 https://wiki.archlinux.org/index.php/SSMTP 참조

2. mail 유틸 (메일 명령어 사용) 설치

$ sudo apt-get install -y mailutils

$ echo "Mail test" | mail -s "Subject" youremail@domain.com