CentOS 搭建postfix邮件服务器 配置php mail

1. 为邮件服务器添加DNS解析

虽然不加DNS解析也能把邮件发出去,但会被大多数邮件服务器当作垃圾邮件。根据我们的实际经验,需要添加三条DNS解析记录:A记录、MX记录、TXT记录。比如域名cnblogs.info,对应的DNS记录如下:

2.安装postfix

yum install -y postfix

3.配置postfix

postfix是CentOS默认安装的邮件服务器软件。以下配置示例假设要配置的域名是boolaw.cn,邮件服务器主机名是mail.boolaw.cn。

1. 打开postfix的配置文件

vi /etc/postfix/main.cf

2. :75 光标移至第75行,修改myhostname

myhostname = mail.boolaw.cn

3. :83 光标移至第83行,修改mydomain

mydomain = boolaw.cn

4. :99 光标移至第99行,修改myorigin

myorigin = $mydomain

5. :116光标移至第116行,修改inet_interfaces

inet_interfaces = all

6. :119光标移至第119行,修改inet_protocols

inet_protocols = ipv4

7. :164光标移至第164行,添加$mydomain

mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

8. :264光标移至第264行,修改mynetworks

mynetworks = 127.0.0.0/8

子网掩码(netmask)转换器:Network and IP address calculator

9. :419 光标移至第419行,设置home_mailbox

home_mailbox = Maildir/

10. :425 光标移至第425行,设置mail_spool_directory,/data是之前挂载的数据盘,mail目录需要通过mkdir命令创建

mail_spool_directory = /data/mail

11. 重启postfix使设置生效

service postfix restart

三、用telnet测试邮件服务器是否正常

1. 在邮件服务器上安装telnet

yum install telnet

2. 连接服务器SMTP端口

telnet 127.0.0.1 25

3. 填写发件人

MAIL FROM:<test@cnblogs.info>

回车

4. 填写收件人

RCPT TO:contact@cnblogs.com 

回车

5. 撰写邮件内容

5.1 开始写邮件内容

DATA                   

回车

5.2 输入标题

Subject: test message

回车

5.3 输入内容,并以.号结束

test body
.

如果显示下面的信息,说明邮件进入发送队列

250 2.0.0 Ok: queued as 88D6D32A94


配置mail函数

使用命令打开编辑php.ini

vi /usr/local/php/etc/php.ini

输入?sendmail_path 查找定位(或者手动跳转找到sendmail_path),你会发现默认是下面的代码

;sendmail_path =

按 i 进入编辑,将这行修改为

sendmail_path = /usr/sbin/sendmail -t -i

按 Esc 键退出编辑,输入 :wq 保存退出

重启php-fpm进程
/etc/init.d/php-fpm restart
测试

echo mail(“66498@qq.com","My subject","测试");


发布了14 篇原创文章 · 获赞 0 · 访问量 2万+
展开阅读全文

postfix邮件服务器,疯狂向外发送垃圾邮件

02-07

公司postfix邮件服务器,一直存在有被别人当做肉鸡在本地向外发送垃圾邮件一直 以来没有解决,下面为配置文件 queue_directory = /var/spool/postfix command_directory = /usr/sbin daemon_directory = /usr/libexec/postfix data_directory = /var/lib/postfix mail_owner = postfix myhostname = mail.cm.com mydomain = cm.com myorigin = $mydomain inet_interfaces = all inet_protocols = ipv4 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain unknown_local_recipient_reject_code = 550 alias_maps = hash:/etc/aliases recipient_delimiter = + home_mailbox = Maildir/ mailbox_command = /usr/bin/procmail -a "$EXTENSION" DEFAULT=$HOME/Maildir/ MAILDIR=$HOME/Maildir header_checks = regexp:/etc/postfix/header_checks body_checks = regexp:/etc/postfix/body_checks smtpd_banner = $myhostname ESMTP debug_peer_level = 2 debugger_command = PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin ddd $daemon_directory/$process_name $process_id & sleep 5 sendmail_path = /usr/sbin/sendmail.postfix newaliases_path = /usr/bin/newaliases.postfix mailq_path = /usr/bin/mailq.postfix setgid_group = postdrop html_directory = no manpage_directory = /usr/share/man sample_directory = /usr/share/doc/postfix-2.6.6/samples readme_directory = /usr/share/doc/postfix-2.6.6/README_FILES message_size_limit = 1000000000 mailbox_size_limit = 2000000000 smtpd_sasl_type = dovecot smtpd_sasl_path = private/auth smtpd_sasl_auth_enable = yes smtpd_sasl_local_domain = $myhostname smtpd_recipient_restrictions = permit_mynetworks permit_auth_destination permit_sasl_authenticated check_policy_service unix:postgrey/socket reject smtpd_use_tls = yes smtpd_tls_cert_file = /etc/pki/tls/certs/server.crt smtpd_tls_key_file = /etc/pki/tls/certs/server.key smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache virtual_alias_maps = hash:/etc/postfix/virtual.ultra-ts.com.cn recipient_bcc_maps = hash:/etc/postfix/bcc_map smtpd_tls_security_level = may content_filter = scan:127.0.0.1:10025 smtpd_milters = inet:127.0.0.1:8891 non_smtpd_milters = $smtpd_milters milter_default_action = accept ####添加邮件队列处理时间设置 queue_run_delay = 300s maximal_queue_lifetime = 2d bounce_queue_lifetime = 2d minimal_backoff_time = 300s maximal_backoff_time = 4000s #设置队列发送限制 anvil_rate_time_unit = 120s smtpd_client_connection_rate_limit = 80 以下为攻击邮件内容 *** ENVELOPE RECORDS deferred/8/83BB3C077A *** message_size: 14844 5319 50 0 14844 message_arrival_time: Wed Feb 7 05:37:03 2018 create_time: Wed Feb 7 05:37:03 2018 named_attribute: rewrite_context=remote sender: apply@kroger.com named_attribute: log_client_name=unknown named_attribute: log_client_address=185.234.216.130 named_attribute: log_client_port=49272 named_attribute: log_message_origin=unknown[185.234.216.130] named_attribute: log_helo_name=185.234.216.130 named_attribute: log_protocol_name=ESMTP named_attribute: client_name=localhost named_attribute: reverse_client_name=localhost named_attribute: client_address=127.0.0.1 named_attribute: client_port=52020 named_attribute: helo_name=mail..com named_attribute: protocol_name=ESMTP named_attribute: client_address_type=2 named_attribute: dsn_orig_rcpt=rfc822;babygrl37907@aol.com original_recipient: babygrl37907@aol.com recipient: babygrl37907@aol.com *** MESSAGE CONTENTS deferred/8/83BB3C077A *** Received: from mail..com (localhost [127.0.0.1]) by mail..com (Postfix) with ESMTP id 83BB3C077A; Wed, 7 Feb 2018 05:37:03 +0800 (CST) Received: from 185.234.216.130 (unknown [185.234.216.130]) by mail..com (Postfix) with ESMTPA id 1884DC0778; Wed, 7 Feb 2018 05:36:52 +0800 (CST) Message-ID: <999C2A7972A6882BF7F2BB06D2327C72@185.234.216.130> Reply-To: "Kroger" <no-relpy@korger.com> From: "Kroger" <apply@kroger.com> Subject: Job Offer Date: Tue, 6 Feb 2018 13:36:51 -0800 Organization: Kroger MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0FF8_01D39F4F.8B8469E0" X-Priority: 3 X-Virus-Scanned: ClamAV using ClamSMTP 因收件人IP较多(有200多人)就不全部复制了,包括中间还有好多垃圾邮件的内容(广告) 如需进一步沟通 lmlhaozi@163.com ,谢谢指导 ,必有重谢 问答

postfix不能发送邮件,发送邮件卡住

05-08

服务器已经搭建好了,但是发送不出去,如下图就一直卡在那里 ![图片说明](https://img-ask.csdn.net/upload/201505/08/1431087621_493620.png) 我使用的是云服务器 下面是我的main.cf配置 myhostname = 10-4-22-248 // 10-4-22-248 这个是我用hostname命令查询出来的,不知道这样对不 mydomain = fandy.com.cn//我的域名 myorigin = $mydomain inet_interfaces = all mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain local_recipient_maps = #smtpd_banner 然后这个参数需要怎么配置,目前我注释掉了 //下面这段是在网上找的,我也就那么放进去了 //在main.cf文件的底部加上以下内容 smtpd_sasl_auth_enable = yes //使用SMTP认证 broken_sasl_auth_clients = yes //让不支持RFC2554的smtpclient也可以跟postfix做交互。 smtpd_sasl_local_domain = $myhostname // 指定SMTP认证的本地域名 smtpd_sasl_security_options = noanonymous //取消匿名登陆方式 smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //设定邮件中有关收件人部分的限制 smtpd_sasl_security_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination //设置允许范围 message_size_limit = 15728640 //邮件大小 mailbox_transport=lmtp:unix:/var/lib/imap/socket/lmtp //设置连接cyrus-imapd的路径 cyrus-sasl配置 [root@localhost postfix]# vim /etc/sasl2/smtpd.conf //在文件尾部加上以下内容 log_level: 3 //记录log的模式 saslauthd_path:/var/run/saslauthd/mux //设置一下smtp寻找cyrus-sasl的路径 然后我执行 netstat -tpnl |grep smtpd 没有任何监听,不清楚是为什么 请问下我的配置出了什么问题吗?我其他的都可以启动的 我安装了 yum install postfix yum install cyrus* 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览