寻觅生命中的那一片浅草......

文章带标签 Postfix

Postfix里Maildir和Mailbox 的区别

版权声明:本文可以任意转载,转载时请保持文章的完整性,并以超链接形式标明文章原始出处和作者信息及本声明。

http://geoffl.blog.163.com/

作者: 富贵猫

前阵子开始要做Postfix邮件服务器,网上搜了好多文章,不过大部分文章只是作者自己安装步骤的罗列,只能算授人以鱼,所以我看了之后还是需要去看Postfix的手册,还要看很多官方的参考书,看完之后颇有心得,所以就打算写一个“授人以渔”的系列安装设置的文章,让你知其然也知其所以然。

——————————————————————————–

Postfix作邮箱,有4种设置方式,分别是共享域名+系统帐户、独立域名+系统帐户、独立域名+虚拟帐户和虚拟域名+特殊格式邮箱。鉴于通常我们不可能给每个用户设置一个系统帐户,所以第一第二种就不考虑不介绍了。既然是用Postfix来建立我们自己地邮箱系统,所以也没必要去兜很多圈子设置特殊格式邮箱,所以第四种也不考虑。剩下只有一种方式,就是独立域名+虚拟邮箱。

所谓独立域名,就是即使用户名是一样的,但如果域名不同其邮件也将放置在不同的目录。譬如info@abc.com和info@def.com,这二个e-mail地址都以info为用户名,但域名不同,如果是共享域名,他们的mail将被放置在同一个目录下,而独立域名将放置在不同目录下。如果你们公司是很大的集团,下面分好几个公司,分别有独立的域名,这难免有重名的员工,这种情况下,后者显然是我们希望看到的。而所谓虚拟帐户,既然那些邮箱用户只是使用mail服务,我们当然没有必要去给每个用户在Linux下面开设一个个系统帐户,所以我们就用一些数据库之类的东西来保存这些帐户信息,譬如用哈希表、SQL数据库或者LDAP。我使用的是独立域名+虚拟LDAP帐户。

Postfix的安装我就不说了,非常简单。不过如果不会也没关系,后面我会写一篇关于Postfix+mail quota的,那时候需要下载、补丁和编译,等于是Postfix的安装。

LDAP也不说了,要完全掌握LDAP不是这篇能解决的,我只假设你的LDAP服务器里已经有mail这个字段。

下面开始说Postfix如何设置。Postfix的配置文件是/etc/postfix/main.cf,这是独立域名+LDAP的设置

# ===== Basic Setting =====
mail_owner = postfix
myhostname = pop.test.com
inet_interfaces = all
queue_directory = /var/spool/postfix
mynetworks = 127.0.0.0/8

home_mailbox =

# ===== Virtual Mailbox =====
virtual_mailbox_domains = hash:/etc/postfix/v_domains
virtual_mailbox_maps = ldap:/etc/postfix/v_mailbox_maps

virtual_mailbox_base = /var/spool/vhosts/
virtual_minimum_uid = 500
virtual_uid_maps = static:5000
virtual_gid_maps = static:5000
virtual_transport = virtual

myhostname设置你的邮件服务器名字

inet_interfaces = all设置你在哪些网卡上监听

另外有几个是需要解释的:我们接受哪些域名的邮件?我们的域名下有哪些用户?他们的邮件存放在什么目录?

我们接受那些域名的邮件,这是由virtual_mailbox_domains来定义的。虽然我们可以直接使用

virtual_mailbox_domains = test.com, test2.com

这样的格式来定义这些域名,不过我还是建议如我这样使用一个表来存放,这样更方便日后的维护,表名是随意取的,有没有后缀都没关系,我用v_domains作为表的名字,在main.cf里定义是

virtual_mailbox_domains = hash:/etc/postfix/v_domains

v_domains的内容如下

test.com OK

test2.com OK

这是个text文件,仅仅包含域名,但为了满足哈希表的格式,所以在后面添加一个OK。然后我们还要把这个文件变成Postfix的数据库格式,因此用如下命令转变其格式

postmap v_domains

之后你会得到一个以db为后缀的文件v_domains.db。注意,每次修改完v_domains你都需要使用一次postmap。

我们有哪些用户,这是由virtual_mailbox_maps来决定。同样,你可以用哈希表,不过我还是用LDAP。为了方便你理解,我先说明一下如果用哈希表,它的格式应该是

user1@test.com test.com/user1_mailDirectory/

user2@test.com test.com/user2_mailDirectory/

user1@test2.com test2.com/user1_mailDirectory/

左边是用户的e-mail地址,空格之后是该用户的邮件存放目录。既然我们说了,独立域名代表info@abc.com和info@def.com的邮件放置在不同目录下,所以我们的定义里user1@test.com和user1@test2.com的目录是不同的。如果换成LDAP,我们要得到相同的结果,即用e-mail地址来搜索,得到其邮件存放目录

既然讲到邮件存放目录,就一并解释一下到底这个目录怎样定义的。邮件是存放在

virtual_mailbox_base\virtual_mailbox_maps\home_mailbox下,也就是说virtual_mailbox_base定义的目录下,postfix会根据virtual_mailbox_maps返回的用户目录自动创建该目录,然后如果home_mailbox也有定义,那么在用户目录下还会创建home_mailbox定义的名字。举例来说,按照上面的设置,邮件会存放在

/var/spool/vhosts/test.com/user1/下面。

如果home_mailbox不是空白而是Mail/,那么就会存放在

/var/spool/vhost/test/com/user1/Mail/下面。home_mailbox有什么用呢?举个例子,比方你已经有homeDirectory了,但那是你平时放文件的地方,那么再在同样目录下放邮件就变得很奇怪,所以需要home_mailbox来定义邮件放在你homeDirectory下的什么目录下

注意:地址的最后有没有”/”决定了使用mailbox格式还是maildir格式,没有”/”表示mailbox,有表示maildir。所以并不象大部分人认为的,home_mailbox定义为MailDir才表示使用maildir格式。再举几个例子

/var/spool/vhosts/test.com/user1/  表示使用MailDir格式

/var/spool/vhosts/test.com/user1  表示使用MailBox格式

/var/spool/vhosts/test.com/user1/Mail/  表示使用MailDir格式

/var/spool/vhosts/test.com/user1/MailDir/ 表示使用MailDir格式

/var/spool/vhosts/test.com/user1/MailDir 表示使用MailBox格式,即使home_mailbox是maildir,但没有最后的”/”,只能表示使用MailBox格式。同样道理

/var/spool/vhosts/test.com/user1/MailBox/ 表示使用MailDir格式,虽然home_mailbox是mailbox,但最后的”/”就说明了是使用MailDir格式。

回到virtual_mailbox_maps的LDAP定义,其格式是

virtual_mailbox_maps = ldap:/etc/postfix/v_mailbox_maps

v_mailbox_maps只是一个连接Postfix和LDAP的配置文件,同样文件名是随意取的。v_mailbox_maps的内容是

# LDAP Server的IP地址,我是设在和postfix同一电脑,所以是127.0.0.1

server_host = 127.0.0.1
# 下面这些关于LDAP Search的内容如果你不了解,请学习LDAP

search_base = ou=people,o=test
server_port = 389
bind = yes
bind_dn = cn=root,o=test
bind_pw = <rootpassword>
version = 3

# 下面是关键,我会额外解释

query_filter = (mail=%s)
result_attribute = mail
result_format = %d/%u/

query_filter = (mai=%s)里,query_filter表示搜索用的字段,mail是表示你LDAP里的字段名,%s表示要进入Postfix服务器的那封e-mail的收件人,mail=%s就是搜索LDAP里的mail字段等于收件人的结果。

result_attribute 是LDAP返回的字段,如果你已经在LDAP里定义了譬如homeDirectory或者mailDirectory这样的字段来存放邮件目录,那么你可以直接使用

result_attribute = homeDirectory

这样的格式来定义,那么它直接返回你定义的homeDirectory,而且不需要后面的result_format。我没有这个字段,但我想把用户邮件放在各自的域名下,就如user1@test.com在test.com/user1/下一样,所以我只需要它返回mail字段,然后用result_format来改变返回字段的格式。result_format顾名思义就是把结果format一下,其中%d表示e-mail地址@之后的域名,d应该是domain的首字母,%u表示e-mail地址@之前的用户名,想来u就是username之类的,所以返回的mail地址user1@test.com经过result_format之后就变成了test.com/user1/。注意,%d/%u/最后那个”/”表示我使用MailDir格式存放我的e-mail。

virtual_uid_maps = static:5000
virtual_gid_maps = static:5000

这2行表示邮件用什么身份的用户来存放,我定义了5000,所以你需要事先添加一个用户,并且其uid是5000

useradd postfixadmin –u 5000

名字是随意取的,只要注意uid和main.cf里这2行的定义相同就OK.

好了,如果一切顺利,你应该已经可以收到mail了,收件人没有存在在你LDAP里的那些邮件,会被退回。

Howto setup Postfix and policyd-weight

1. Read the changelog
1.1. Download policyd-weight
Depending on the bugfixes (see changelog) download the appropriate release:

or if quot;devel&quot; sounds more exciting:

Move policyd-weight to the proper location for your operating system (example shows *BSD

):

# mv policyd-weight /usr/local/libexec/postfix/policyd-weight
# chmod 0555 /usr/local/libexec/postfix/policyd-weight

Check the default settings

# /usr/local/libexec/postfix/policyd-weight defaults

If these settings seem appropriate you don&#39;t need a configuration file at all. In case you like to change some settings, create a file (i.e. /usr/local/etc/policyd-weight.conf) and add only the variables that differ from the defaults. For example if you want only DNSBL checks and a different port use:

# —————————————————————-
#  minimal configuration for policyd-weight
# —————————————————————-
$dnsbl_checks_only = 1;
$TCP_PORT &nbsp;  &nbsp;  &nbsp;  = 12336;

There is another option, which is not recommended:

# /usr/local/libexec/postfix/policyd-weight defaults &gt; /usr/local/etc/policyd-weight.conf
# chmod 0644 /usr/local/etc/policyd-weight.conf

This will write the default configuration to a file. However, this is not good practice, because it will make maintaining the configuration file difficult and changed defaults will not picked up automatically.
2.1 Add a system account for policyd-weight
Use the appropriate commands for your operating system to add a new user and a new group named polw. This unprivileged user does not need a valid shell.
2.2 Create an init script
Either create an rc-init script or manage otherwise that policyd-weight gets started at boot-time. The command to start policyd-weight in daemon mode is:

# /path/to/policyd-weight start

You need to be root to do that.
3. Edit Postfix main.cf
This example shows a minimal setup. Do NOT copy & paste, instead adjust your main.cf to meet the minimal requirements. Please keep old authentication restrictions (such as SASL) and so forth:

01:  smtpd_helo_required = yes &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;   # required
02:  smtpd_delay_reject = yes &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; # suggested
03:
04:  smtpd_helo_restrictions =
05: &nbsp;  &nbsp; permit_mynetworks, &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;   # suggested
06: &nbsp;  &nbsp; reject_invalid_hostname &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; # suggested
07:
08:  smtpd_client_restrictions = permit_mynetworks &nbsp;  &nbsp; # suggested
09:
10:  smtpd_sender_restrictions = permit_mynetworks &nbsp;  &nbsp; # suggested
11:
12:  smtpd_recipient_restrictions =
13: &nbsp;  &nbsp; permit_mynetworks, &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;   # required
14: &nbsp;  &nbsp; … other authed permits …
15: &nbsp;  &nbsp; … (permit_sasl_authenticated) …
16: &nbsp;  &nbsp; reject_unauth_destination, &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; # required
17: &nbsp;  &nbsp; reject_unauth_pipelining, &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  # suggested
18: &nbsp;  &nbsp; … whitelists (role accounts, clients) …
19: &nbsp;  &nbsp; reject_non_fqdn_recipient, &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp;  &nbsp; # suggested
20: &nbsp;  &nbsp; check_policy_service inet:127.0.0.1:12525 &nbsp;  &nbsp; # required

Lines 6: makes sure to only allow valid DNS Names (in terms of [RFC 2821] Sect. 2.3.5, [RFC 1123] Sect. 5.2.5 and [RFC 1035] Sect. 2.3.1) in the HELO command. reject_invalid_hostname (or reject_invalid_helo_hostname as of Postfix 2.3.x) makes sure that no bogus characters are used. It&#39;s a safety and RFC setting.

Line 20: calls the policy daemon on host 127.0.0.1 (localhost) at port 12525.
For whitelisting hosts read the FAQ.

To prevent that a proper MTA can use your own domain as sender please read and unterstand Ralf Hildebrandts receipe

If you don&#39;t understand some settings or don&#39;t know their meaning please read Postfix SMTP relay and access control first, respectively the postconf.5 manpage.
4. Score tuning and other configurations
To tune scores or turn on/off some features such as X-headers, read and edit /usr/local/etc/policyd-weight.conf
The configuration file is Perl syntax. If you make Perl syntax errors there, policyd-weight won&#39;t work.
It is not required to restart or reload postfix. Changes made to the configuration are picked up by each new policyd-weight instance. To have changes take effect immediately you can a) kill each policyd-weight instance, or b) restart Postfix if running in master.cf mode.

转载自:http://www.thismail.org/bbs/thread-2044-1-1.html

postfix权威指南笔记

pcre perl兼容正则表达式

postconf -m 查看postfix支持的函数

postmap -q 测试任何种类的查询表

postmap -q hash:/etc/postfix/transport
postmap -q mysql:/etc/postfix/transport.cf

postalias

postfix check
检查配置文件是否有问题,文件与目录的拥有权是否正确,甚至帮你创建任何遗失的目录,

postfix的等效机制是定义在main.cf的queue_run_delay参数,默认值是1000秒

postfix -D 得出调试信息

/etc/services —查看下文件内容

postsuper -h 保留邮件队列

postsuper -H 将保留的邮件队列重新激活

postsuper -r ALL 将被延迟了的邮件重新排队

postcat -q 邮件ID 查看一个队列文件的内容

要求postfix立刻投递滞留在队列里的邮件的操作成为清空(flush),
命令是 postqueue -f

postqueue -s 清空寄到特定站点的邮件

postconf -l 查看postfix支持的锁机制

最简单的虚拟网域模式,是每位用户都可以收到每个网域的邮件。就用户的感受而言,
就好像同一个邮箱有多个地址一样。这种模式的设定方法最简单,只要将所有虚拟网域名称都列在mydestination参数,并像平常一样为每一位用户(不管他们在哪一个网域)都创建自己的系统账户,他们就可以收到写给任何网域的邮件。

默认情况下,flush只管理relay_domains所列的网域。如果还有其他网域也需要快速清空服务,你可以将它们的网域名称列在fast_flush_domains

CentOS5.2、5.3上安装ispCP OMEGA

IspCP Omega 简单介绍:
IspCP 是作为另一款开源虚拟主机管理系统VHCS2的替代产品,采用Apache2+PHP5(fastcgi模式,支持每个虚机独立的php.ini)+MySQL5(提供内置的phpmyadmin)提供 Web 服务(也支持传统的 CGI),FTP 采用 Proftpd(也支持 webftp 功能),邮件是 postfix+courier+squirrermail,和 IspCPH管理平台(PHP 代码,支持管理员、代理商、虚拟主机用户三级用户,相互之间可以自由切换,自由增加子域名、FTP、MySQL、Mail 账号),另外对于每个虚拟主机都有独立的每天完整备份机制(可以用 FTP 下载)。

系统:CentOS5.2,无桌面,安装开发工具,开发库

一、禁用SELinux
# vi /etc/selinux/config

SELINUX=enforcing
修改为
SELINUX=disabled

# vi /etc/sysconfig/network
将HOSTNAME修改为
HOSTNAME=test.test.com

iptables没必要禁了,ispCP安装好后,会生成防火墙规则,并启用iptables

重启系统
# init 6
阅读全文»

发信去Gmail问题

This is the Postfix program at host www.example.net.

I’m sorry to have to inform you that the message returned
below could not be delivered to one or more destinations.

For further assistance, please send mail to <postmaster>

If you do so, please include this problem report. You can
delete your own text from the message returned below.

阅读全文»

2024年四月
« 5月    
1234567
891011121314
15161718192021
22232425262728
2930