您的位置:首页 > 运维架构 > Linux

Linux下搭建mutt+msmtp发送邮件

2015-12-26 14:50 519 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/cz493354115/article/details/50408549

1.自动安装

apt-get install mutt

apt-get install msmtp

 

vi /root/.msmtp.log  //配置msmtp的日志文件

 

root@newbie:~# mkdir -p/usr/local/msmtp/etc

 

root@newbie:~# vi/root/.msmtprc //配置msmtp的配置文件

defaults

account 163mail

host smtp.163.com

port 25

tls off

auth login

from 13668157273@163.com

user 13668157273

password hzmburxvynxaakvx   //这里的密码,如果163邮箱开启了客户端验证,则不能输入邮箱密码

logfile /root/.msmtp.log

account default: 163mail                 

 

root@newbie:~# chmod 600 /root/.msmtprc  //修改权限

 

root@newbie:~# vi/root/.muttrc  //配置mutt的配置文件

setsendmail="/usr/bin/msmtp"

set use_from=yes

set realname="name"   //设置发件人姓名

set from=13668157273@163.com

set envelope_from=yes

 

root@newbie:~#  msmtp -P //测试配置文件root@newbie:~# msmtp -P

ignoring system configuration file/etc/msmtprc: 没有那个文件或目录

loaded user configuration file/root/.msmtprc

falling back to default account

using account default from/root/.msmtprc

host                  = smtp.163.com

port                  = 25

timeout               = off

protocol              = smtp

domain                = localhost

auth                  = LOGIN

user                  = 13668157273

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                  = 13668157273@163.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 commandline

 

root@newbie:~#  msmtp -S //测试smtp服务器

SMTP server at smtp.163.com(smtp.163.com [123.125.50.133]), port 25:

   163.com Anti-spam GT for Coremail System (163com[20141201])

Capabilities:

   PIPELINING:

        Support for command grouping for fastertransmission

   STARTTLS:

        Support for TLS encryption via theSTARTTLS command

   AUTH:

        Supported authentication methods:

        PLAIN LOGIN

This server might advertise more orother capabilities when TLS is active.

 

 

出现cannot locatehost smtp.126.com

解决方案:

vi /etc/hosts

123.125.50.133  smtp.163.com

 

如果是多个收件人,那么使用空格或者逗号分开即可,测试命令:

 

echo "testmail" |mutt -s "测试"  XXXX@qq.comXXXX@126.com

 

 

msmtp的配置问题

 

如果是普通用户使用mutt+msmtp,可能会出现邮件发不出去的问题,如果上面步骤的配置文件不是设置在 ~/ 目录下的,这里可能是配置文件出了问题。

 

msmtp首先去读每个用户目录下的配置文件,比如root用户默认的配置文件路径为: /root/.msmtprc

     cz用户默认的配置文件路径为:  /home/cz/.msmtprc  (注意这里有.msmtprc)

如果没有读到这个配置文件,则去读系统配置文件 /etc/msmtprc。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: