编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

详解Centos7部署sendmail发送邮件教程,值得收藏

wxchong 2024-06-24 19:46:30 开源技术 45 ℃ 0 评论

概述

sendmail是linux系统中一个邮箱系统, 也是一个免费、轻量级、命令行的SMTP邮件客户端。如果你需要使用命令行方式发送邮件,那么sendEmail是非常完美的选择:使用简单、功能强大。

下面介绍下sendmail安装部署部分,以下基于centos7系统测试。


1、sendmail的配置文件

/etc/mail/sendmail.cf :Sendmail的主配置文件;
/etc/mail/access :中继访问控制;
/etc/mail/domaintable ;域名映射;
/etc/mail/local-host-names ;本地主机别名;
/etc/mail/mailertable :为特定的域指定特殊的路由规则;
/etc/mail/virtusertable :虚拟域配置。

中继的配置:

是指一台服务器接受并传递源地址和目的地址都不是本服务器的邮件。

在两个文件中进行设置:

/etc/mail/relay-domains
/etc/mail/access

2、安装sendmail

yum install -y sendmail
yum install -y sendmail-cf

启动saslauthd服务进行SMTP验证(默认是安装的,如果没有,就手动安装)

service saslauthd start

3、邮件服务配置(iptables防火墙关闭)

1)配置Senmail的SMTP认证

将下面两行内容前面的dnl去掉。在sendmail文件中,dnl表示该行为注释行,是无效的,因此通过去除行首的dnl字符串可以开启相应的设置行。

# vim /etc/mail/sendmail.mc
......
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

2) 设置Sendmail服务的网络访问权限

将127.0.0.1改为0.0.0.0,意思是任何主机都可以访问Sendmail服务。

如果仅让某一个网段能够访问到Sendmail服务,将127.0.0.1改为形如192.168.1.0/24的一个特定网段地址。

# vim /etc/mail/sendmail.mc
......
DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl

3)生成配置文件

Sendmail的配置文件由m4来生成,m4工具在sendmail-cf包中。如果系统无法识别m4命令,说明sendmail-cf软件包没有安装

# m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

4)启动服务(如果发现sendmail dead but subsys locked,那就执行"service postfix status"查看postfix是否默认开启了,如果开启的话,就关闭postfix,然后再启动或重启sendmail服务即可。)

# service sendmail start
# service saslauthd restart

5)将服务加入自启行列

# chkconfig sendmail on
# chkconfig saslauthd on
# chkconfig --list |grep sendmail
# chkconfig --list |grep saslauthd

6)安装mailx

# yum -y install mailx

4、配置指定发送邮箱

RHEL(Oracle Linxu/CentOS)系统下,如果使用sendmail发送邮件,如果不特殊设置,一般发件箱地址为user@hostname

1) Sendmail配置

配置发送邮件的邮箱认证信息

vi /etc/mail.rc

--- 增加如下内容 ---
set from=yourname@your-domain.com
set smtp=mail.your-domain.com
set smtp-auth-user=yourname
set smtp-auth-password=yourpasswd
set smtp-auth=login

2)测试发送邮件功能

echo "hello word" | mail -s "mail title" yourname@your-domain.com
--报错:could not connect: Connection timed out
"/root/dead.letter" 11/305
. . . message not sent.
排查1:smtp服务器地址dns解析无误
排查2:smtp服务器端口25是否可以访问;

3)查看邮箱


篇幅有限,这块内容就介绍到这了,后面会分享更多devops和DBA方面的内容,感兴趣的朋友可以关注下~

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表