安装配置msmtp和mutt
最近看到有人问如何登录域名外的邮箱发邮件,通过在网上进行搜索并实验,现在把msmtp及mutt发邮件的配置过程记录一下,以备用。
1、效果测试:
发送邮件:
安装配置msmtp和mutt_mutt 
接收邮件:
 安装配置msmtp和mutt_邮件_02
2、安装配置msmtp
A.    下载msmtp:
msmtp-1.4.28.tar MD5cd3683339986433aea09f189cc69d4db
[root@21:50:03 soft]# tar -xvf msmtp-1.4.28.tar
[root@21:50:02 soft]# ls
msmtp-1.4.28 msmtp-1.4.28.tar
B.     安装:
[root@21:50:02 soft]# ./configure
[root@21:50:02 soft]# make
[root@21:50:02 soft]# make install
C.    配置:
在用户要目录下创建esmtprc
[root@21:50:02  ~]# cat .esmtprc
# Default value for all following accounts
defaults
#    tls on
#    tls_trust_file /etc/ssl/certs/ca-certificates.crt
#   keepbcc on
#   未使用TLS,注释掉
# --------msmtp 日志 -----------
    logfile ~/.msmtp.log
 
# --------定义默认设置 ----------
# Gmail
account gmail
    host smtp.gmail.com
    port 587
    auth login
 
account hunt1574@gmail.com : gmail
    from hunt1574@gmail.com
    user "hunt1574"
    password "123456"
# ------- hunt1574@gmail.com 引用了默认设置Gmail的设置。-------
 
# ------- 也可以按以下设置 --------------
# Another mail service
account another_mailbox@domain.com
    host smtp.163.com
    auth login
    from hunt1574@163.com
    user "hunt1574"
    password "123456"
 
# Default account
account default : hunt1574@gmail.com
 
 
配置文件.msmtprc中包含了明文的密码,最好将权限设置为仅当前用户可读写:
[root@22:13:07 ~]# chmod 600 .msmtprc
D.    测试
[root@22:19:33 ~]# msmtp –P
----查看配置文件的内容
ignoring system configuration file /usr/local/etc/msmtprc: 没有那个文件或目录
----此处提示不要紧,可以将.msmtprc内容写至/usr/local/etc/msmtprc
loaded user configuration file /root/.msmtprc
falling back to default account
using account default from /root/.msmtprc
host                 
= smtp.gmail.com   
port                 
= 587              
timeout              
= off              
protocol             
= smtp             
domain               
= localhost        
auth                 
= LOGIN            
user                 
= hunt1574         
password             
= *                
passwordeval         
= (not set)        
ntlmdomain            
= (not set)        
tls                  
= off              
tls_starttls         
= on               
tls_trust_file       
= (not set)        
tls_crl_file         
= (not set)        
tls_fingerprint      
= (not set)        
tls_key_file         
= (not set)        
tls_cert_file        
= (not set)        
tls_certcheck        
= on               
tls_force_sslv3      
= off              
tls_min_dh_prime_bits
= (not set)        
tls_priorities       
= (not set)        
auto_from            
= off              
maildomain           
= (not set)        
from                 
= hunt1574@gmail.com
dsn_notify           
= (not set)        
dsn_return           
= (not set)        
keepbcc               
= off              
logfile              
= /root/.msmtp.log 
syslog               
= (not set)        
aliases              
= (not set)        
reading recipients from the command line
 
[root@22:28:09 ~]# date | msmtp hunt1574@foxmail.com -d
ignoring system configuration file /usr/local/etc/msmtprc: 没有那个文件或目录
loaded user configuration file /root/.msmtprc
falling back to default account
using account default from /root/.msmtprc
host                 
= smtp.gmail.com   
port                  
= 587              
timeout              
= off              
protocol             
= smtp             
domain               
= localhost        
auth                 
= LOGIN            
user                 
= hunt1574         
password             
= *                
passwordeval         
= (not set)        
ntlmdomain           
= (not set)        
tls                  
= off              
tls_starttls         
= on               
tls_trust_file       
= (not set)        
tls_crl_file         
= (not set)        
tls_fingerprint      
= (not set)        
tls_key_file         
= (not set)        
tls_cert_file        
= (not set)        
tls_certcheck        
= on               
tls_force_sslv3       
= off              
tls_min_dh_prime_bits
= (not set)        
tls_priorities       
= (not set)        
auto_from            
= off              
maildomain           
= (not set)        
from                 
= hunt1574@gmail.com
dsn_notify           
= (not set)        
dsn_return           
= (not set)        
keepbcc              
= off              
logfile              
= /root/.msmtp.log 
syslog               
= (not set)        
aliases              
= (not set)        
reading recipients from the command line
 
<-- 220 **********
--> EHLO localhost
<-- 250-gmail.com HELO, pleased to meet localhost
<-- 250-AUTH=LOGIN PLAIN
<-- 250-AUTH LOGIN PLAIN
<-- 250-PIPELINING
<-- 250 8BITMIME
--> AUTH LOGIN
<-- 334 VXNl11cm5hbWU6
--> Y2hhaXp2vbmduYW4=
<-- 334 UGF3zc3dvcmQ6
--> bm1nMT32UwMTI0
<-- 235 go ahead
--> MAIL FROM:<hunt1574@gmail.com>
--> RCPT TO:<hunt1574@foxmail.com>
--> DATA
<-- 250 OK
<-- 250 OK
<-- 354 go ahead
--> 2012 05 11日星期五 22:28:43 CST
--> .
<-- 250 OK:has queued
--> QUIT
<-- 221 close connection
 
[root@22:32:10 ~]# cat .msmtp.log
 5 11 22:28:44 host=smtp.gmail.com tls=off auth=on user=hunt1574 from=hunt1574@gmail.com recipients=hunt1574@foxmail.com mailsize=37 smtpstatus=250 smtpmsg='250 OK:has queued' exitcode=EX_OK
 
查收邮件为一封无主题代发邮件。
 
3Mutt的安装及配置
A.    安装mutt:
一般情况下Mutt已随系统安装:
                   [root@22:39:09 ~]# rpm -qa | grep mutt
mutt-1.4.2.2-3.0.2.el5
若未安装,请自行google
B.     配置
在用户要目录下创建.muttrc
[root@22:50:02  ~]# cat .muttrc
set sendmail="/usr/local/bin/msmtp"
set use_from=yes
set from="hunt1574 < hunt1574@gmail.com >"
set envelope_from=yes
set sendmail_wait=0
此内容参考:
按官方的配置示例也可将以下内容加入/etc/muttrc:
set from=" hunt1574@gmail.com"
set sendmail="/usr/local/bin/msmtp"
set use_from=yes
set realname=" hunt1574 "
set editor="vi"
※ 加入到/etc/muttrc 与当前用户创建.muttrc先其一即可。
C.    测试:
     [root@22:55:23 ~]# echo -e "msmtp test\n by : hunt1574" | mutt -s "msmtp finished" hunt1574@foxmail.com
 
最后:
通过修改.muttrc 中的set from="hunt1574 < hunt1574@gmail.com >"可伪造任意发件人。
 安装配置msmtp和mutt_邮件_03
 
foxmail失败了,估计TX做了限制。