安装配置msmtp和mutt
安装配置msmtp和mutt
最近看到有人问如何登录域名外的邮箱发邮件,通过在网上进行搜索并实验,现在把msmtp及mutt发邮件的配置过程记录一下,以备用。
1、效果测试:
发送邮件:
接收邮件:
2、安装配置msmtp
A. 下载msmtp:
msmtp-1.4.28.tar MD5:cd3683339986433aea09f189cc69d4db
[[email protected]:50:03 soft]# tar -xvf msmtp-1.4.28.tar
[[email protected]:50:02 soft]# ls
msmtp-1.4.28 msmtp-1.4.28.tar
B. 安装:
[[email protected]:50:02 soft]# ./configure
[[email protected]:50:02 soft]# make
[[email protected]:50:02 soft]# make install
C. 配置:
在用户要目录下创建esmtprc
[[email protected]: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 [email protected] : gmail
from [email protected]
user "hunt1574"
password "123456"
# ------- [email protected] 引用了默认设置Gmail的设置。-------
# ------- 也可以按以下设置 --------------
# Another mail service
account [email protected]
host smtp.163.com
auth login
from [email protected]
user "hunt1574"
password "123456"
# Default account
account default : [email protected]
配置文件.msmtprc中包含了明文的密码,最好将权限设置为仅当前用户可读写:
[[email protected]:13:07 ~]# chmod 600 .msmtprc
D. 测试
[[email protected]: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
|
|
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
[[email protected]:28:09 ~]# date | msmtp [email protected] -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
|
|
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:<[email protected]>
--> RCPT TO:<[email protected]>
--> DATA
<-- 250 OK
<-- 250 OK
<-- 354 go ahead
--> 2012年 05月 11日星期五 22:28:43 CST
--> .
<-- 250 OK:has queued
--> QUIT
<-- 221 close connection
[[email protected]:32:10 ~]# cat .msmtp.log
5月 11 22:28:44 host=smtp.gmail.com tls=off auth=on user=hunt1574 [email protected] [email protected] mailsize=37 smtpstatus=250 smtpmsg='250 OK:has queued' exitcode=EX_OK
查收邮件为一封无主题代发邮件。
3、Mutt的安装及配置
A. 安装mutt:
一般情况下Mutt已随系统安装:
[[email protected]:39:09 ~]# rpm -qa | grep mutt
mutt-1.4.2.2-3.0.2.el5
若未安装,请自行google。
B. 配置
在用户要目录下创建.muttrc
[[email protected]:50:02 ~]# cat .muttrc
set sendmail="/usr/local/bin/msmtp"
set use_from=yes
set from="hunt1574 < [email protected] >"
set envelope_from=yes
set sendmail_wait=0
此内容参考:
按官方的配置示例也可将以下内容加入/etc/muttrc中:
set from=" [email protected]"
set sendmail="/usr/local/bin/msmtp"
set use_from=yes
set realname=" hunt1574 "
set editor="vi"
※ 加入到/etc/muttrc 与当前用户创建.muttrc先其一即可。
C. 测试:
[[email protected]:55:23 ~]# echo -e "msmtp test\n by : hunt1574" | mutt -s "msmtp finished" [email protected]
最后:
通过修改.muttrc 中的set from="hunt1574 < [email protected] >"可伪造任意发件人。
发foxmail失败了,估计TX做了限制。
转载于:https://blog.51cto.com/hunt1574/861407