CentOS 7.3 配置postfix并发送邮件

查看系统版本
[root@nginx01 ~]# uname -nrm
nginx01 3.10.0-514.el7.x86_64 x86_64
[root@nginx01 ~]# uname -a
Linux nginx01 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[root@nginx01 ~]#

安装postfix作为邮件MAT
[root@nginx01 ~]# yum install postfix

安装mailx作为发送邮件客户端
[root@nginx01 ~]# yum install mailx

检查是否安装成功
[root@nginx01 ~]# rpm -qa | grep -E 'postfix|mailx'
mailx-12.5-16.el7.x86_64
postfix-2.10.1-6.el7.x86_64
[root@nginx01 ~]#

检查上述postfix和mailx安装了那些文件

[root@nginx01 ~]# rpm -ql postfix
/etc/pam.d/smtp
/etc/pam.d/smtp.postfix
/etc/postfix
/etc/postfix/access
/etc/postfix/canonical
/etc/postfix/generic
/etc/postfix/header_checks
/etc/postfix/main.cf
/etc/postfix/master.cf
/etc/postfix/relocated
/etc/postfix/transport
/etc/postfix/virtual
/etc/sasl2/smtpd.conf
/usr/bin/mailq
/usr/bin/mailq.postfix
/usr/bin/newaliases
/usr/bin/newaliases.postfix
/usr/bin/rmail
/usr/bin/rmail.postfix
/usr/lib/sendmail
/usr/lib/sendmail.postfix
/usr/lib/systemd/system/postfix.service
/usr/libexec/postfix
/usr/libexec/postfix/aliasesdb
/usr/libexec/postfix/anvil
/usr/libexec/postfix/bounce
/usr/libexec/postfix/chroot-update
/usr/libexec/postfix/cleanup
/usr/libexec/postfix/discard
/usr/libexec/postfix/dnsblog
/usr/libexec/postfix/error
/usr/libexec/postfix/flush
/usr/libexec/postfix/lmtp
/usr/libexec/postfix/local
/usr/libexec/postfix/main.cf
/usr/libexec/postfix/master
/usr/libexec/postfix/master.cf
/usr/libexec/postfix/nqmgr
/usr/libexec/postfix/oqmgr
/usr/libexec/postfix/pickup
/usr/libexec/postfix/pipe
/usr/libexec/postfix/post-install
/usr/libexec/postfix/postfix-files
/usr/libexec/postfix/postfix-script
/usr/libexec/postfix/postfix-wrapper
/usr/libexec/postfix/postmulti-script
/usr/libexec/postfix/postscreen
/usr/libexec/postfix/proxymap
/usr/libexec/postfix/qmgr
/usr/libexec/postfix/qmqpd
/usr/libexec/postfix/scache
/usr/libexec/postfix/showq
/usr/libexec/postfix/smtp
/usr/libexec/postfix/smtpd
/usr/libexec/postfix/spawn
/usr/libexec/postfix/tlsmgr
/usr/libexec/postfix/tlsproxy
/usr/libexec/postfix/trivial-rewrite
/usr/libexec/postfix/verify
/usr/libexec/postfix/virtual
/usr/sbin/postalias
/usr/sbin/postcat
/usr/sbin/postconf
/usr/sbin/postdrop
/usr/sbin/postfix
/usr/sbin/postkick
/usr/sbin/postlock
/usr/sbin/postlog
/usr/sbin/postmap
/usr/sbin/postmulti
/usr/sbin/postqueue
/usr/sbin/postsuper
/usr/sbin/sendmail
/usr/sbin/sendmail.postfix
/usr/sbin/smtp-sink
/usr/sbin/smtp-source
/usr/share/doc/postfix-2.10.1
/usr/share/doc/postfix-2.10.1/COMPATIBILITY
/usr/share/doc/postfix-2.10.1/LICENSE
/usr/share/doc/postfix-2.10.1/README-Postfix-SASL-RedHat.txt
/usr/share/doc/postfix-2.10.1/README_FILES
/usr/share/doc/postfix-2.10.1/README_FILES/AAAREADME
/usr/share/doc/postfix-2.10.1/README_FILES/ADDRESS_CLASS_README
/usr/share/doc/postfix-2.10.1/README_FILES/ADDRESS_REWRITING_README
/usr/share/doc/postfix-2.10.1/README_FILES/ADDRESS_VERIFICATION_README
/usr/share/doc/postfix-2.10.1/README_FILES/BACKSCATTER_README
/usr/share/doc/postfix-2.10.1/README_FILES/BASIC_CONFIGURATION_README
/usr/share/doc/postfix-2.10.1/README_FILES/BUILTIN_FILTER_README
/usr/share/doc/postfix-2.10.1/README_FILES/CDB_README
/usr/share/doc/postfix-2.10.1/README_FILES/CONNECTION_CACHE_README
/usr/share/doc/postfix-2.10.1/README_FILES/CONTENT_INSPECTION_README
/usr/share/doc/postfix-2.10.1/README_FILES/DATABASE_README
/usr/share/doc/postfix-2.10.1/README_FILES/DB_README
/usr/share/doc/postfix-2.10.1/README_FILES/DEBUG_README
/usr/share/doc/postfix-2.10.1/README_FILES/DSN_README
/usr/share/doc/postfix-2.10.1/README_FILES/ETRN_README
/usr/share/doc/postfix-2.10.1/README_FILES/FILTER_README
/usr/share/doc/postfix-2.10.1/README_FILES/INSTALL
/usr/share/doc/postfix-2.10.1/README_FILES/IPV6_README
/usr/share/doc/postfix-2.10.1/README_FILES/LDAP_README
/usr/share/doc/postfix-2.10.1/README_FILES/LINUX_README
/usr/share/doc/postfix-2.10.1/README_FILES/LOCAL_RECIPIENT_README
/usr/share/doc/postfix-2.10.1/README_FILES/MAILDROP_README
/usr/share/doc/postfix-2.10.1/README_FILES/MEMCACHE_README
/usr/share/doc/postfix-2.10.1/README_FILES/MILTER_README
/usr/share/doc/postfix-2.10.1/README_FILES/MULTI_INSTANCE_README
/usr/share/doc/postfix-2.10.1/README_FILES/MYSQL_README
/usr/share/doc/postfix-2.10.1/README_FILES/NFS_README
/usr/share/doc/postfix-2.10.1/README_FILES/OVERVIEW
/usr/share/doc/postfix-2.10.1/README_FILES/PACKAGE_README
/usr/share/doc/postfix-2.10.1/README_FILES/PCRE_README
/usr/share/doc/postfix-2.10.1/README_FILES/PGSQL_README
/usr/share/doc/postfix-2.10.1/README_FILES/POSTSCREEN_README
/usr/share/doc/postfix-2.10.1/README_FILES/QSHAPE_README
/usr/share/doc/postfix-2.10.1/README_FILES/RELEASE_NOTES
/usr/share/doc/postfix-2.10.1/README_FILES/RESTRICTION_CLASS_README
/usr/share/doc/postfix-2.10.1/README_FILES/SASL_README
/usr/share/doc/postfix-2.10.1/README_FILES/SCHEDULER_README
/usr/share/doc/postfix-2.10.1/README_FILES/SMTPD_ACCESS_README
/usr/share/doc/postfix-2.10.1/README_FILES/SMTPD_POLICY_README
/usr/share/doc/postfix-2.10.1/README_FILES/SMTPD_PROXY_README
/usr/share/doc/postfix-2.10.1/README_FILES/SOHO_README
/usr/share/doc/postfix-2.10.1/README_FILES/SQLITE_README
/usr/share/doc/postfix-2.10.1/README_FILES/STANDARD_CONFIGURATION_README
/usr/share/doc/postfix-2.10.1/README_FILES/STRESS_README
/usr/share/doc/postfix-2.10.1/README_FILES/TLS_LEGACY_README
/usr/share/doc/postfix-2.10.1/README_FILES/TLS_README
/usr/share/doc/postfix-2.10.1/README_FILES/TUNING_README
/usr/share/doc/postfix-2.10.1/README_FILES/ULTRIX_README
/usr/share/doc/postfix-2.10.1/README_FILES/UUCP_README
/usr/share/doc/postfix-2.10.1/README_FILES/VERP_README
/usr/share/doc/postfix-2.10.1/README_FILES/VIRTUAL_README
/usr/share/doc/postfix-2.10.1/README_FILES/XCLIENT_README
/usr/share/doc/postfix-2.10.1/README_FILES/XFORWARD_README
/usr/share/doc/postfix-2.10.1/TLS_ACKNOWLEDGEMENTS
/usr/share/doc/postfix-2.10.1/TLS_LICENSE
/usr/share/doc/postfix-2.10.1/bounce.cf.default
/usr/share/doc/postfix-2.10.1/examples
/usr/share/doc/postfix-2.10.1/examples/chroot-setup
/usr/share/doc/postfix-2.10.1/examples/chroot-setup/LINUX2
/usr/share/doc/postfix-2.10.1/examples/qmail-local
/usr/share/doc/postfix-2.10.1/examples/qmail-local/qmail-local.txt
/usr/share/doc/postfix-2.10.1/examples/smtpd-policy
/usr/share/doc/postfix-2.10.1/examples/smtpd-policy/README.SPF
/usr/share/doc/postfix-2.10.1/examples/smtpd-policy/greylist.pl
/usr/share/doc/postfix-2.10.1/main.cf.default
/usr/share/man/man1/mailq.1.gz
/usr/share/man/man1/mailq.postfix.1.gz
/usr/share/man/man1/newaliases.1.gz
/usr/share/man/man1/newaliases.postfix.1.gz
/usr/share/man/man1/postalias.1.gz
/usr/share/man/man1/postcat.1.gz
/usr/share/man/man1/postconf.1.gz
/usr/share/man/man1/postdrop.1.gz
/usr/share/man/man1/postfix.1.gz
/usr/share/man/man1/postkick.1.gz
/usr/share/man/man1/postlock.1.gz
/usr/share/man/man1/postlog.1.gz
/usr/share/man/man1/postmap.1.gz
/usr/share/man/man1/postmulti.1.gz
/usr/share/man/man1/postqueue.1.gz
/usr/share/man/man1/postsuper.1.gz
/usr/share/man/man1/sendmail.postfix.1.gz
/usr/share/man/man1/smtp-sink.1.gz
/usr/share/man/man1/smtp-source.1.gz
/usr/share/man/man5/access.5.gz
/usr/share/man/man5/aliases.5.gz
/usr/share/man/man5/aliases.postfix.5.gz
/usr/share/man/man5/body_checks.5.gz
/usr/share/man/man5/bounce.5.gz
/usr/share/man/man5/canonical.5.gz
/usr/share/man/man5/cidr_table.5.gz
/usr/share/man/man5/generic.5.gz
/usr/share/man/man5/header_checks.5.gz
/usr/share/man/man5/ldap_table.5.gz
/usr/share/man/man5/master.5.gz
/usr/share/man/man5/memcache_table.5.gz
/usr/share/man/man5/mysql_table.5.gz
/usr/share/man/man5/nisplus_table.5.gz
/usr/share/man/man5/pcre_table.5.gz
/usr/share/man/man5/pgsql_table.5.gz
/usr/share/man/man5/postconf.5.gz
/usr/share/man/man5/postfix-wrapper.5.gz
/usr/share/man/man5/regexp_table.5.gz
/usr/share/man/man5/relocated.5.gz
/usr/share/man/man5/sqlite_table.5.gz
/usr/share/man/man5/tcp_table.5.gz
/usr/share/man/man5/transport.5.gz
/usr/share/man/man5/virtual.5.gz
/usr/share/man/man8/anvil.8.gz
/usr/share/man/man8/bounce.8.gz
/usr/share/man/man8/cleanup.8.gz
/usr/share/man/man8/defer.8.gz
/usr/share/man/man8/discard.8.gz
/usr/share/man/man8/dnsblog.8.gz
/usr/share/man/man8/error.8.gz
/usr/share/man/man8/flush.8.gz
/usr/share/man/man8/lmtp.8.gz
/usr/share/man/man8/local.8.gz
/usr/share/man/man8/master.8.gz
/usr/share/man/man8/oqmgr.8.gz
/usr/share/man/man8/pickup.8.gz
/usr/share/man/man8/pipe.8.gz
/usr/share/man/man8/postscreen.8.gz
/usr/share/man/man8/proxymap.8.gz
/usr/share/man/man8/qmgr.8.gz
/usr/share/man/man8/qmqpd.8.gz
/usr/share/man/man8/scache.8.gz
/usr/share/man/man8/sendmail.8.gz
/usr/share/man/man8/showq.8.gz
/usr/share/man/man8/smtp.8.gz
/usr/share/man/man8/smtpd.8.gz
/usr/share/man/man8/spawn.8.gz
/usr/share/man/man8/tlsmgr.8.gz
/usr/share/man/man8/tlsproxy.8.gz
/usr/share/man/man8/trace.8.gz
/usr/share/man/man8/trivial-rewrite.8.gz
/usr/share/man/man8/verify.8.gz
/usr/share/man/man8/virtual.8.gz
/var/lib/misc/postfix.aliasesdb-stamp
/var/lib/postfix
/var/spool/postfix
/var/spool/postfix/active
/var/spool/postfix/bounce
/var/spool/postfix/corrupt
/var/spool/postfix/defer
/var/spool/postfix/deferred
/var/spool/postfix/flush
/var/spool/postfix/hold
/var/spool/postfix/incoming
/var/spool/postfix/maildrop
/var/spool/postfix/pid
/var/spool/postfix/private
/var/spool/postfix/public
/var/spool/postfix/saved
/var/spool/postfix/trace
[root@nginx01 ~]# rpm -ql mailx
/bin/mail
/bin/mailx
/etc/mail.rc
/usr/bin/Mail
/usr/bin/nail
/usr/share/doc/mailx-12.5
/usr/share/doc/mailx-12.5/AUTHORS
/usr/share/doc/mailx-12.5/COPYING
/usr/share/doc/mailx-12.5/README
/usr/share/man/man1/Mail.1.gz
/usr/share/man/man1/mail.1.gz
/usr/share/man/man1/mailx.1.gz
/usr/share/man/man1/nail.1.gz
[root@nginx01 ~]#

配置系统发送邮件的地址

[root@nginx01 log]# cp -p /etc/postfix/main.cf /etc/postfix/main.cf.bk.20180504

[root@nginx01 log]# vi /etc/postfix/main.cf

[root@nginx01 log]# diff /etc/postfix/main.cf /etc/postfix/main.cf.bk.20180504
75c75
< myhostname = nginx01.com

#myhostname = host.domain.tld

重启postfix
[root@nginx01 ~]# systemctl restart postfix
[root@nginx01 ~]# ps -ef |grep postfix
root 21998 1 0 19:15 ? 00:00:00 /usr/libexec/postfix/master -w
postfix 21999 21998 0 19:15 ? 00:00:00 pickup -l -t unix -u
postfix 22000 21998 0 19:15 ? 00:00:00 qmgr -l -t unix -u
root 22017 18319 0 19:15 pts/1 00:00:00 grep --color=auto postfix
[root@nginx01 ~]# netstat -antup | grep 25
tcp 0 0 127.0.0.1:25 0.0.0.0: LISTEN 21998/master
tcp6 0 0 ::1:25 :::
LISTEN 21998/master
[root@nginx01 ~]#

发送邮件测试是否成功

[root@nginx01 ~]# echo "test4 from nginx01" | mail -s "test4 from nginx01" test@test.com

检查log

[root@nginx01 log]# tail -5 maillog
May 4 18:57:06 nginx01 postfix/pickup[18269]: 5256C1009A4E: uid=0 from=<root>
May 4 18:57:06 nginx01 postfix/cleanup[19183]: 5256C1009A4E: message-id=<20180504105706.5256C1009A4E@nginx01.com>
May 4 18:57:06 nginx01 postfix/qmgr[18270]: 5256C1009A4E: from=<root@nginx01.com>, size=449, nrcpt=1 (queue active)
May 4 18:57:11 nginx01 postfix/smtp[19185]: 5256C1009A4E: to=<test@test.com>, relay=test.com[121.210.168.231]:25, delay=4.8, delays=0.09/0.05/0.11/4.5, dsn=2.0.0, status=sent (250 OK:has queued)
May 4 18:57:11 nginx01 postfix/qmgr[18270]: 5256C1009A4E: removed
[root@nginx01 log]#

可见发送成功。

转载于:https://blog.51cto.com/guanhaizhan/2112611

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值