天天看點

Linux下配置用msmtp和mutt發郵件

Linux下可以直接用mail指令發送郵件,但是發件人是user@servername,如果機器沒有外網的dns,其他人就無法回複。此時,有一個可以使用網絡免費郵箱服務的郵件發送程式就比較重要了。msmtp就是這樣的一個程式。

#1、下載下傳源碼包

wget http://sourceforge.net/projects/msmtp/files/msmtp/1.4.31/msmtp-1.4.31.tar.bz2/download

#2、解壓

tar -jxvf msmtp-1.4.31.tar.bz2 && cd msmtp-1.4.31

#build and install

./configure --prefix=/usr/local/msmtp && make && make install

#link to /usr/bin

ln -s /usr/local/msmtp/bin/msmtp /usr/bin/msmtp

#3、建立msmtp的配置檔案

mkdir /usr/local/msmtp/etc 

mkdir /var/log/msmtp/

vim /usr/local/msmtp/etc/msmtprc

#4、輸入如下内容

# Set default values for all following accounts.

defaults

logfile /var/log/msmtp/msmtp.log

# The SMTP server of the provider.

account 163

# SMTP郵件伺服器位址

host smtp.163.com

# 發送的郵件Email

from [email protected]

auth login

# 郵件伺服器登入賬号

user [email protected]

# 郵件伺服器登陸密碼

password password

# Set a default account

account default : 163

#5、測試msmtp是否配置正确

msmtp [email protected]

[ctrl+d]

#6、安裝配置mutt

yum install -y mutt

vim /etc/Muttrc

#輸入如下内容:

set sendmail='/usr/bin/msmtp'

set use_from=yes

set realname="[email protected]"

set [email protected]

好了,讓我們來測試一下吧!

echo "testmail" | mutt -s "測試" -a /etc/hosts [email protected]

這裡的-a 是指添加附件,如果是多個附件的話就 多加幾個 -a 檔案名

還可以這樣

mutt -s "測試" -a /etc/hosts -a /etc/apple [email protected] < /tmp/imax.txt

這個的意思就是以 /tmp/imax.txt 檔案的内容作為郵件内容。

echo "This is the body" | mutt -s "Testing" [email protected] -a /etc/hosts -a /etc/apple

好了,就這麼簡單

本文轉自leonardos51CTO部落格,原文連結: http://blog.51cto.com/leomars/1771341,如需轉載請自行聯系原作者

繼續閱讀