以下是自己收集的实用Linux下简单配置外部邮箱发送邮件的方法:

1、配置/etc/mail.rc,使用mail命令

# vim /etc/mail.rc

###调用外部邮箱  
set [email protected]    
set smtp=smtp.exmail.qq.com 
set [email protected]    
set smtp-auth-password="XXXXXX"

set smtp-auth=login

然后使用mail命令即可发送邮件了

2、msmtp+mutt方式

msmtp下载地址:https://sourceforge.net/projects/msmtp/files/msmtp/

1)安装msmtp

# wget http://heanet.dl.sourceforge.net/project/msmtp/msmtp/1.6.5/msmtp-1.6.5.tar.xz

# xz -d msmtp-1.6.5.tar.xz

# tar xvf msmtp-1.6.5.tar

# cd msmtp-1.6.5

# ./configure --prefix=/usr/local/msmtp

# make && make install

2)配置msmtp

# vim ~/.msmtprc                                       
account default    
host smtp.exmail.qq.com    
from [email protected]

user [email protected]

password XXXXXX

auth login  
logfile ~/.msmtp.log

3)安装配置mutt

# yum install mutt -y

# vim /etc/Muttrc

set sendmail="/usr/local/msmtp/bin/msmtp"  
set use_from=yes     
set realname="XXXXXX"    
set editor="vim"

4)发送邮件

# echo "这里是正文" |mutt -s "这里是标题" [email protected]


5)报错排查

echo "Email" |mutt -s"test" [email protected]

msmtp: envelope from address root@ not accepted by the server

msmtp: server message: 501 mail from address must be same as authorization user

msmtp: could not send mail (account default from /usr/local/msmtp/etc/msmtprc)

Error sending message, child exited 65 (Data format error.).

Could not send the message.


修改/etc/Muttrc:

set sendmail="/usr/local/msmtp/bin/msmtp"

set use_from=yes

set envelope_from="yes"

set realname="[email protected]"

set editor="vim"

set from="[email protected]"