CentOS 7.5 下配置sendmail外部邮箱

62 篇文章 1 订阅
24 篇文章 0 订阅

CentOS下配置sendmail外部邮箱

 

这里写图片描述

Sendmail是linux/unix下广泛被使用的一款邮件服务器,这篇文章将会介绍如何在centos7上安装和设定邮箱以便能够正常发送邮件,由于本地邮箱会被大部分邮件服务器认定为垃圾邮件甚至直接拦截,本文以163邮箱为例介绍一下如何使用以及一些常见的问题。

安装

项目说明安装命令
sendmailsendmail服务器yum install sendmail -y
mailx邮件发送服务yum install mailx -y

安装结果确认

[root@angular ~]# rpm -qa |egrep 'sendmail|mailx'
sendmail-8.14.7-5.el7.x86_64
mailx-12.5-16.el7.x86_64
[root@angular ~]# 

邮件设定

设定/etc/hosts

由于shendmail会从/etc/hosts中确认domain name和host name,请将/etc/hosts中的配置信息加上,比如:

[root@angular ~]# grep angular /etc/hosts
192.168.163.151 angular.com angular
[root@angular ~]# 

常见问题:
此处如不设定,启动sendmail服务时会提示如下问题:

angular sendmail[44298]: My unqualified host name (angular) unknown; sleeping for retry
angular sendmail[44298]: unable to qualify my own domain name (angular) -- using short name

注意hostname的修改往往也会是sendmail不能正常动作的元凶,所以对机器的设定无比考虑到影响。

设定/etc/sysconfig/network

因为本文需要通过外部163的信箱进行发送,可以做如下设定

[root@angular ~]# cat /etc/sysconfig/network
# Created by anaconda
hostname mail.163.com
[root@angular ~]# 

常见问题:
此处如不设定,发送mail时一般会提示如下问题:

smtp-server: 535 Error: authentication failed

设定/etc/mail.rc

将/etc/mail.rc中添加如下信息, 使用smtp方式进行验证。

# Set from address and smtp domain
set from=xxxxxxxx@163.com smtp=smtp.163.com

# Set Smtp authentication 
set smtp-auth-user=xxxxxx@163.com smtp-auth-password=xxxx smtp-auth=login

 

常见问题:
此处出现的可能性问题较多,比如邮箱写错,空格问题,密码写错等等, 比如密码写错时会提示如下信息:

smtp-server: 535 Error: authentication failed

 

注意:密码修改该之后,一般不用重启sendmail服务即可起作用,所以修改的时候注意影响。
另外请注意各种邮箱不同一般设定也会有所不同,比如上述密码,163的邮箱不是登陆密码,而是授权码,需要在登陆邮箱在服务器侧设定,发送服务很多时候根据邮箱的不同设定方法有所不同,千万注意。

验证

发送邮件

使用下面简单的mail命令即可发送一封信给liumiaocn@outlook.com

项目说明
Frommail.rc中设定的邮箱
Toliumiaocn@outlook.com
TitleGreeting from liumiaocn
MessageHello, this is a test mail
[root@angular ~]# echo "Hello, this is a test mail" |mail -s "Greeting from liumiaocn" liumiaocn@outlook.com
[root@angular ~]# 

接收确认

这里写图片描述

问题追踪

日志文件

碰到问题,建议确认日志文件的信息

日志文件:/var/log/maillog

sendmail的debug模式

使用sendmail的debug模式,可以更好的逐步排查问题:

使用方式:sendmail -bt -d

[root@angular ~]# sendmail -bt -d
Version 8.14.7
 Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
        MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
        NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF SOCKETMAP STARTTLS
        TCPWRAPPERS USERDB USE_LDAP_INIT
getla(): 0.09
setoption SevenBitInput (7)=False
setoption AliasWait (a)=10
setoption AliasFile (A)=/etc/aliases
setoption MinFreeBlocks (b)=100
setoption BlankSub (B)=.
setoption HoldExpensive (c)=False
setoption DeliveryMode (d)=background
setoption TempFileMode (F)=0600
setoption HelpFile (H)=/etc/mail/helpfile
setoption SendMimeErrors (j)=True
setoption ForwardPath (J)= 0x81 z/.forward. 0x81 w: 0x81 z/.forward
setoption ConnectionCacheSize (k)=2
setoption ConnectionCacheTimeout (K)=5m
setoption UseErrorsTo (l)=False
setoption LogLevel (L)=9
setoption CheckAliases (n)=False
setoption OldStyleHeaders (o)=True
setoption DaemonPortOptions (O)=Port=smtp,Addr=127.0.0.1, Name=MTA
Daemon MTA flags: 
setoption PrivacyOptions (p)=authwarnings,novrfy,noexpn,restrictqrun
setoption QueueDirectory (Q)=/var/spool/mqueue
setoption Timeout (r).connect=1m
setoption Timeout (r).ident=0
setoption Timeout (r).queuereturn=5d
setoption Timeout (r).queuewarn=4h
setoption SuperSafe (s)=True
setoption StatusFile (S)=/var/log/mail/statistics
setoption DefaultUser (u)=8:12
setoption UserDatabaseSpec (U)=/etc/mail/userdb.db
setoption TryNullMXList (w)=True
setoption SmtpGreetingMessage (0x90)= 0x81 j Sendmail  0x81 v/ 0x81 Z;  0x81 b
setoption UnixFromLine (0x91)=From  0x81 g  0x81 d
setoption OperatorChars (0x92)=.:%@!^/[]+
setoption DontProbeInterfaces (0xa1)=True
setoption AuthOptions (0xbd)=A
drop_privileges(1): Real[UG]id=0:0, get[ug]id=0:0, gete[ug]id=0:51, RunAs[UG]id=0:0
getauthinfo: root@localhost

============ SYSTEM IDENTITY (after readcf) ============
      (short domain name) $w = angular
  (canonical domain name) $j = angular.com
         (subdomain name) $m = com
              (node name) $k = angular
========================================================

setoption HoldExpensive (c)=F
setoption DeliveryMode (d)=
assign_queueid: assigned id vAGMmR3I050207, e=0x7f6a6a982aa0
ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
Enter <ruleset> <address>
>

总结

这篇文章介绍了sendmail的安装和设定方法,以及常见的问题和解决方法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值