創建所需條目

Example 1. postfix-ldap.ldif

debian:/etc/postfix# cat postfix-ldap.ldif
#dn: dc=example,dc=net
#objectclass:person
#objectclass:organization
#cn:example
#sn:example
#o:example.net
#description:Top level of directory

dn: ou=people,dc=example,dc=net
ou: people
objectClass: organizationalUnit

dn: ou=postfix,dc=example,dc=net
ou: postfix
objectClass: organizationalUnit

dn: cn=courier, ou=postfix, dc=example,dc=net
objectClass: person
cn: courier
sn: courier
			

虛擬域

# example.net, postfix, example.net
dn: vd=example.net,ou=postfix,dc=example,dc=net
vd: example.net
o: example.net
transport: virtual:
objectClass: postfixVirtualDomain
			

Example 2. user.ldif

本地域郵箱

dn:uid=neo,ou=postfix,dc=example,dc=net
uid:neo
cn:test
sn:test
mail:neo
uidnumber:1001
gidnumber:1001
mailhost:mail.example.net
homedirectory:/var/mail/
mailbox:example.net/neo/Maildir/
quota:200000000s,20000c
maildrop:openunix@163.com
userpassword:{crypt}$1$8E.vtK6o$7JdJ6dpTwaLU7x8X2FKwc1
#clearPassword:chen
AccountStatus:true
objectclass:postfixAccount
objectclass:person
			

Qmail 風格

dn:uid=neo,ou=postfix,dc=example,dc=net
uid:neo
cn:test
sn:test
mail:neo
uidnumber:1001
gidnumber:1001
mailhost:mail.example.net
homedirectory:/var/mail/
mailmessagestore:example.net/neo/Maildir/
mailquota:200000000s,20000c
#mailbox:example.net/chen/maildir/
userpassword:chen
#clearPassword:chen
objectclass:postfix
#objectclass:couriermailaccount
objectclass:person
			

Note

mail:neo

neo = noe+ mydomain(main.cf中設置)

虛擬或郵箱

dn:uid=test,ou=postfix,dc=example,dc=net
uid:test
cn:test
sn:test
mail:test
uidnumber:1001
gidnumber:1001
mailhost:mail.example.net
homedirectory:/var/mail/
mailbox:example.net/test/Maildir/
quota:200000000s,20000c
userpassword:{crypt}$1$8E.vtK6o$7JdJ6dpTwaLU7x8X2FKwc1
#clearPassword:chen
AccountStatus:true
objectclass:postfixAccount
objectclass:person
			

Qmail 風格

dn:uid=test,ou=postfix,dc=example,dc=net
uid:test
cn:test
sn:test
mail:test@example.net
uidnumber:1001
gidnumber:1001
mailhost:mail.example.net
homedirectory:/var/mail/
mailmessagestore:example.net/test/Maildir/
mailquota:200000000s,20000c
#mailbox:example.net/chen/maildir/
userpassword:chen
#clearPassword:chen
objectclass:postfix
#objectclass:couriermailaccount
objectclass:person
			

Note

虛擬域郵箱在smtp認證時要使用email地址即認證用戶帳號:test@example.net而非test

創建dn

ldapadd -x -D "cn=admin,dc=example,dc=net" -f /etc/postfix/postfix-ldap.ldif -w chen
ldapadd -x -D "cn=admin,dc=example,dc=net" -f /etc/postfix/user.ldif -w chen
adding new entry "uid=test,ou=postfix,dc=example,dc=net"

debian:/etc/postfix# ldapsearch -x -b 'dc=example,dc=net' 'objectclass=*'
# extended LDIF
#
# LDAPv3
# base <dc=example,dc=net> with scope sub
# filter: objectclass=*
# requesting: ALL
#

# example.net
dn: dc=example,dc=net
objectClass: top
objectClass: dcObject
objectClass: organization
o: postfix
dc: example

# admin, example.net
dn: cn=admin,dc=example,dc=net
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
description: LDAP administrator

# people, example.net
dn: ou=people,dc=example,dc=net
ou: people
objectClass: organizationalUnit

# postfix, example.net
dn: ou=postfix,dc=example,dc=net
ou: postfix
objectClass: organizationalUnit

# courier, postfix, example.net
dn: cn=courier,ou=postfix,dc=example,dc=net
objectClass: person
cn: courier
sn: courier

# example.net, postfix, example.net
dn: vd=example.net,ou=postfix,dc=example,dc=net
vd: example.net
o: example.net
transport: virtual:
objectClass: postfixVirtualDomain

# chen, postfix, example.net
dn: uid=chen,ou=postfix,dc=example,dc=net
uid: chen
cn: chen
sn: chen
mail: chen@example.net
uidNumber: 1001
gidNumber: 1001
mailHost: mail.example.net
homeDirectory: /var/mail/
mailbox: example.net/chen/maildir/
quota: 200000000s,20000c
maildrop:: Y2hlbkBleGFtcGxlLm5ldCAg
accountStatus: true
objectClass: postfixAccount
objectClass: person

# test, postfix, example.net
dn: uid=test,ou=postfix,dc=example,dc=net
uid: test
cn: test
sn: test
mail: test
uidNumber: 1001
gidNumber: 1001
mailHost: mail.example.net
homeDirectory: /var/mail/
mailbox: example.net/test/Maildir/
quota: 200000000s,20000c
accountStatus: true
objectClass: postfixAccount
objectClass: person

# neo, postfix, example.net
dn: uid=neo,ou=postfix,dc=example,dc=net
uid: neo
cn: test
sn: test
mail: neo
uidNumber: 1001
gidNumber: 1001
mailHost: mail.example.net
homeDirectory: /var/mail/
mailbox: example.net/neo/Maildir/
quota: 200000000s,20000c
maildrop: openunix@163.com
accountStatus: true
objectClass: postfixAccount
objectClass: person

# search result
search: 2
result: 0 Success

# numResponses: 10
# numEntries: 9
debian:/etc/postfix#