Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | Github | OSChina 博客 | 云社区 | 云栖社区 | Facebook | Linkedin | 知乎专栏 | 视频教程 | About

4.2. 配置 Postfix

4.2.1. 转发配置

修改配置文件

				vim /etc/postfix/main.cf

				inet_interfaces = all

				mydestination =

				mydomain = example.com

				myhostname = mail.example.com

				mynetworks = 0.0.0.0/0

				mynetworks_style = subnet

				smtpd_reject_unlisted_recipient = no

				transport_maps = hash:/etc/postfix/transport
			

转发配置,设置域名和地址的关系:

				vim transport:

				your.com relay: [10.10.0.1]
			

生成相应的db文件

				postmap transport
			

例如当收件人为users@your.com时,postfix会将邮件转发到指定的服务器

4.2.2. 拒收垃圾邮件

编辑/etc/postfix/main.cf文件,在文件中添加下面一行文字,你可以把它插入到文件末尾。

				sudo vim /etc/postfix/main.cf

				smtpd_recipient_restrictions = check_sender_access hash:/etc/postfix/check_sender_access
			

然后在/etc/postfix/目录下创建一个check_sender_access文件,内容如下

				example.com REJECT
				your.com OK

				.example.com REJECT
				.your.com OK

				user@example.com REJECT
			

将域名的特定邮箱地址添加到黑名单,也可以将某个二级域名添加到黑名单或白名单,只要在域名前面加上一个小数点就行了。邮箱与域名后面输入OK表示将这个域名添加到白名单,域名后面添加REJECT表示将这个域名添加到黑名单。

使用postmap命令创建/etc/postfix/sender_checks.db数据库文件

				postmap /etc/postfix/check_sender_access
			

最后重新加载Postfix配置文件

				sudo /etc/init.d/postfix reload
			

4.2.3. 收件箱配置

Postfix 提供三种收件箱,第一种是Mailbox,第二种是Maildir, 第三种是Unix风格的收件想/var/spool/mail

如你有POP/IMAP服务请使用Mailbox 或者 Maildir。否则仅仅是在 unix上阅读纯文本邮件可以使用/var/spool/mail

4.2.3.1. Mailbox 配置

					home_mailbox = Mailbox
				

4.2.3.2. Maildir 配置

					home_mailbox = Maildir/
				

4.2.3.3. 传统Unix风格邮箱配置

					mail_spool_directory = /var/mail
				
					mail_spool_directory = /var/spool/mail
				

4.2.4. 邮件投递

邮件投递是指从你的Postfix服务器将邮件投到目的地邮件服务器,即 SMTP对SMTP,而非用户到的SMTP配置。

配置主要涉及邮件投递频率,如果过高,会被退回也可能被封锁一段时间。

				* initial_destination_concurrency:到目标主机的初始化并发连接数。
				* default_destination_concurrency_limit:初始化连接后对同一目标主机的最大并发连接数目。
				* local_destination_concurrency_limit:控制对同一本地收件人的最大同时投递的邮件数目。
			

默认值可以通过 $ postconf | grep local_destination_concurrency_limit 命令查看

				initial_destination_concurrency = 5
				default_destination_concurrency_limit = 20
				local_destination_concurrency_limit = 2
			

4.2.5. 队列配置

queue_run_delay 配置间隔多长时间重新发送一次deferred队列的邮件

				# postconf | grep queue_run_delay
				queue_run_delay = 300s
			

deferred邮件队列中的生存时间

				# postconf | grep maximal_queue_lifetime
				maximal_queue_lifetime = 5d
			

队列尺寸

				# postconf | grep qmgr_
				qmgr_clog_warn_time = 300s
				qmgr_daemon_timeout = 1000s
				qmgr_fudge_factor = 100
				qmgr_ipc_timeout = 60s
				qmgr_message_active_limit = 20000
				qmgr_message_recipient_limit = 20000
				qmgr_message_recipient_minimum = 10
			

4.2.6. 客户端

smtpd_client_connection_count_limit 配置邮件客户端链接数,例如 Outlook 用户数量

				# postconf | grep smtpd_client_connection_count_limit
				postscreen_client_connection_count_limit = $smtpd_client_connection_count_limit
				smtpd_client_connection_count_limit = 50
			

控制接收邮件频率

				# postconf | grep smtpd_client_connection_rate_limit
				smtpd_client_connection_rate_limit = 0
			

4.2.7. SMTP 发送权限相关配置

			
neo@netkiller ~ % postconf -n|egrep 'smtpd_recipient_restrictions|smtpd_relay_restrictions'
smtpd_recipient_restrictions = permit_mynetworks
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination permit_inet_interfaces