天天看点

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,如需转载请自行联系原作者

继续阅读