据说 Postfix 的效率更高,不多说,下面是网上搜集的安装配置教程。搬瓦工 Centos 7 x86_64 bbr 环境下亲测可用。
安装方法
yum install postfix
/usr/sbin/alternatives --set mta /usr/sbin/sendmail.postfix
alternatives --display mta | grep postfix
看看显示的是不是:
link currently points to /usr/sbin/sendmail.postfix
/usr/sbin/sendmail.postfix - priority 30
slave mta-pam: /etc/pam.d/smtp.postfix
slave mta-mailq: /usr/bin/mailq.postfix
slave mta-newaliases: /usr/bin/newaliases.postfix
slave mta-rmail: /usr/bin/rmail.postfix
slave mta-sendmail: /usr/lib/sendmail.postfix
slave mta-mailqman: /usr/share/man/man1/mailq.postfix.1.gz
slave mta-newaliasesman: /usr/share/man/man1/newaliases.postfix.1.gz
slave mta-aliasesman: /usr/share/man/man5/aliases.postfix.5.gz
slave mta-sendmailman: /usr/share/man/man1/sendmail.postfix.1.gz
然后是处理 sendmail,任君选择。
//卸载:
rpm -e sendmail
//禁用:
service sendmail stop
chkconfig sendmail off
我这个系统压根是没有安装 sendmail。
配置 Postfix
vi /etc/postfix/main.cf
参考配置,请根据实际分别找到相应项目修改。
myhostname = cyhour.com
mydomain = cyhour.com
myorigin = $mydomain
inet_interfaces = all
inet_protocols = all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mynetworks = 168.100.189.0/28, 127.0.0.0/8
home_mailbox = Maildir/
canonical_maps = hash:/etc/postfix/canonical
vi /etc/postfix/canonical
添加下面类型的代码,意思是默认使用 noreply@cyhour.com 发送邮件。
www noreply@cyhour.com
然后执行下面的代码:
cd /etc/postfix/
postmap canonical
若提示以下错误:
postmap: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
安装 mysql-libs 即可:
yum reinstall mysql-libs -y
启动 Postfix
service postfix start
chkconfig postfix on
service postfix status
netstat -an | grep :25
确认『postfix.service running...』和『tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN』就行。
修改 php 配置
如果没有配置过 sendmail 组件,很可能没有修改 php.ini 的邮件发送路径,会无法发送邮件。
打开 php 配置文件:
vi /usr/local/php/etc/php.ini
输入 ?sendmail_path 查找定位(或者手动跳转找到sendmail_path),将 ;sendmail_path = 改为:
sendmail_path = /usr/sbin/sendmail -t -i
重启 php 进程
/etc/init.d/php-fpm restart
如无意外,至此 Postfix 已经可以发送邮件。
参考文章
kn007 - 今天星期六,周末没下雨,舒服,搞了postfix
倡萌的自留地 - LNMP笔记:Centos下安装Postfix,替换sendmail发送邮件
压缩包解压密码 1024,AdBlock 等插件会阻碍站点资源加载。
配置这个要细心,错个符号都不行 哈哈
我配过,后来嫌麻烦 直接用第三方来代发邮件了
@World 一步一步下来就好,倒是 OpenDKIM 因为 epel 源的问题折腾了许久。
老杨,请教下 centos7 , lamp环境下怎么让contact form7能用呢?从bluehost搬过来vultr,一直处理不好这个问题
@nicholas nack VPS 能发送邮件了吗?还是用第三方邮箱发送呢?
终于找到这个,哈哈 开始折腾……
@灰常记忆 囧,早就发过链接给你吧?