본문 바로가기

Technical/Softwares

mailx로 linux prompt(shell)에서 테스트메일 전송하기(smtp)


Linux prompt에서 간단히 아래의 sample 형태로 smtp 서버를 통해 메일 발송을 테스트해 볼 수 있다. Shell script에서 특정 작업 수행시에 Alert 메일 발송에 응용해볼 수 있겠다.


echo -e "HELLLLLLLLLLLO\nThis is a test mail\nTime: `date +%Y:%m:%d-%H:%M:%S`" | env MAILRC=/dev/null from=admin@frommail.co.kr smtp=mail.frommail.co.kr smtp-auth-user=admin@frommail.co.kr smtp-auth-password=password smtp-auth=login mailx -v -n -s "subject is test for `date +%Y:%m:%d-%H:%M:%S`" mail-rcpt@tomail.co.kr


또는 매일 내용을 mail.txt 와 같은 파일로 저장해두고 아래와 같이 발송할 수도 있다.


env MAILRC=/dev/null from=admin@frommail.co.kr smtp=mail.frommail.co.kr smtp-auth-user=admin@frommail.co.kr smtp-auth-password=password smtp-auth=login mailx -v -n -s "subject is test for `date +%Y:%m:%d-%H:%M:%S`" mail-rcpt@tomail.co.kr < mail.txt


* SMTP접속을 위한 메일 계정이 미리 준비되어 있어야 하며, 아래 2개의 옵션에 기재하여 넣는다.

smtp-auth-user=admin@frommail.co.kr

smtp-auth-password=password


* 여러명에게 발송할 경우에는 mail-rcpt1@tomail.co.kr mail-rcpt2@naver.com 와 같은 형태로 스페이스로 구분하여 연속으로 기재하면 된다.



- Barracuda -