CentOS 7.5 下配置sendmail外部邮箱

怼烎@ 2022-05-18 22:59 250阅读 0赞

CentOS下配置sendmail外部邮箱

这里写图片描述

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

安装





















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

安装结果确认

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

邮件设定

设定/etc/hosts

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

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

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

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

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

设定/etc/sysconfig/network

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

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

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

  1. smtp-server: 535 Error: authentication failed

设定/etc/mail.rc

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

  1. # Set from address and smtp domain
  2. set from=xxxxxxxx@163.com smtp=smtp.163.com
  3. # Set Smtp authentication
  4. set smtp-auth-user=xxxxxx@163.com smtp-auth-password=xxxx smtp-auth=login

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

  1. smtp-server: 535 Error: authentication failed

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

验证

发送邮件

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


























项目 说明
From mail.rc中设定的邮箱
To liumiaocn@outlook.com
Title Greeting from liumiaocn
Message Hello, this is a test mail
  1. [root@angular ~]# echo "Hello, this is a test mail" |mail -s "Greeting from liumiaocn" liumiaocn@outlook.com
  2. [root@angular ~]#

接收确认

这里写图片描述

问题追踪

日志文件

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

日志文件:/var/log/maillog

sendmail的debug模式

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

使用方式:sendmail -bt -d

  1. [root@angular ~]# sendmail -bt -d
  2. Version 8.14.7
  3. Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
  4. MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
  5. NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF SOCKETMAP STARTTLS
  6. TCPWRAPPERS USERDB USE_LDAP_INIT
  7. getla(): 0.09
  8. setoption SevenBitInput (7)=False
  9. setoption AliasWait (a)=10
  10. setoption AliasFile (A)=/etc/aliases
  11. setoption MinFreeBlocks (b)=100
  12. setoption BlankSub (B)=.
  13. setoption HoldExpensive (c)=False
  14. setoption DeliveryMode (d)=background
  15. setoption TempFileMode (F)=0600
  16. setoption HelpFile (H)=/etc/mail/helpfile
  17. setoption SendMimeErrors (j)=True
  18. setoption ForwardPath (J)= 0x81 z/.forward. 0x81 w: 0x81 z/.forward
  19. setoption ConnectionCacheSize (k)=2
  20. setoption ConnectionCacheTimeout (K)=5m
  21. setoption UseErrorsTo (l)=False
  22. setoption LogLevel (L)=9
  23. setoption CheckAliases (n)=False
  24. setoption OldStyleHeaders (o)=True
  25. setoption DaemonPortOptions (O)=Port=smtp,Addr=127.0.0.1, Name=MTA
  26. Daemon MTA flags:
  27. setoption PrivacyOptions (p)=authwarnings,novrfy,noexpn,restrictqrun
  28. setoption QueueDirectory (Q)=/var/spool/mqueue
  29. setoption Timeout (r).connect=1m
  30. setoption Timeout (r).ident=0
  31. setoption Timeout (r).queuereturn=5d
  32. setoption Timeout (r).queuewarn=4h
  33. setoption SuperSafe (s)=True
  34. setoption StatusFile (S)=/var/log/mail/statistics
  35. setoption DefaultUser (u)=8:12
  36. setoption UserDatabaseSpec (U)=/etc/mail/userdb.db
  37. setoption TryNullMXList (w)=True
  38. setoption SmtpGreetingMessage (0x90)= 0x81 j Sendmail 0x81 v/ 0x81 Z; 0x81 b
  39. setoption UnixFromLine (0x91)=From 0x81 g 0x81 d
  40. setoption OperatorChars (0x92)=.:%@!^/[]+
  41. setoption DontProbeInterfaces (0xa1)=True
  42. setoption AuthOptions (0xbd)=A
  43. drop_privileges(1): Real[UG]id=0:0, get[ug]id=0:0, gete[ug]id=0:51, RunAs[UG]id=0:0
  44. getauthinfo: root@localhost
  45. ============ SYSTEM IDENTITY (after readcf) ============
  46. (short domain name) $w = angular
  47. (canonical domain name) $j = angular.com
  48. (subdomain name) $m = com
  49. (node name) $k = angular
  50. ========================================================
  51. setoption HoldExpensive (c)=F
  52. setoption DeliveryMode (d)=
  53. assign_queueid: assigned id vAGMmR3I050207, e=0x7f6a6a982aa0
  54. ADDRESS TEST MODE (ruleset 3 NOT automatically invoked)
  55. Enter <ruleset> <address>
  56. >

总结

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

发表评论

表情:
评论列表 (有 0 条评论,250人围观)

还没有评论,来说两句吧...

相关阅读