2016-07-19 14:12:48 0 Comments Linux Boy.Lee

use MUTT send email from Centos

Sometime we need send email from Centos Server, like backup MySQL Database and sent backup files to email address, we will learn how to send email from Centos' shell.

{Check Install Start sendmail }

//Install
yum install sendmail

//Check
ps -ef | grep sendmail

//Start
service sendmail start

//auto-run
chkconfig --level 2345 sendmail on

{ Check and Install mutt }

//check mutt install, if already installed, will return /usr/bin/mutt
# which mutt

//install mutt
# yum install mutt

{ Config mutt }

Have 2 config way:

  1. config global mutt, direct edit /etc/Muttrc 
  2. config for user level mutt, copy /etc/Muttrc to /curUser/.muttrc
//copy for root user
# cp /etc/Muttrc /root/.muttrc

for above two way, have same config steps

#encode
set charset="utf-8" 

#custom from info
set envelope_from=yes #if not found this one, direct add it manual
set use_from=yes 
set from=yiilib.com@gmail.com
set realname="Master Lee"

 

{ Test Send }

//Language
mutt [-hnpRvxz][-a<file>][-b<addr>][-c<addr>][-f<file>][-F<file>][-H<file>][-i<file>][-m<type>] [-s<subj>][addr]

//this case send mail to boy.lee.here@gmail.com
//Subject "Test Mail Subject"
//Use /root/backup/yiilib.com_tmp.sql as attachment
//Use /root/publicMailBody.txt as mail body
mutt boy.lee.here@mail.com -s "Test Mail Subject" -a /root/backup/yiilib.com_tmp.sql < /root/publicMailBody.txt

//this case send mail to boy.lee.here@gmail.com
//Subject "Test Mail Subject"
//Body "Mail Body"
//Use /root/backup/yiilib.com_tmp.sql as attachment
echo "Mail Body" | mutt boy.lee.here@mail.com -s "Test Mail Subject" -a /root/backup/yiilib.com_tmp.sql