当前位置: 技术问答>linux和unix
ubuntu server IMAP/POP3 Server 怎么配置?
来源: 互联网 发布时间:2016-07-26
本文导语: 公司要用内部邮箱,请问高手怎么配置呀,服务器上有 了 Dovecot IMAP/POP3 Server 了?? | 我在CentOS下装过 我是在日文系统下完成的配置过程 这是当时留下的一点笔记 我改了改 把大概的...
公司要用内部邮箱,请问高手怎么配置呀,服务器上有 了 Dovecot IMAP/POP3 Server 了??
|
我在CentOS下装过 我是在日文系统下完成的配置过程 这是当时留下的一点笔记 我改了改 把大概的步骤写写 希望对你有帮助 Postfix+Dovecot
1.安装好postfix
#vi /etc/postfix/main.cf
# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = mail.xxxx.com ← 追加
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = domain.tld
mydomain = xxxx.com ← 追加(域名指定)
# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites. If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
#myorigin = $myhostname
#myorigin = $mydomain
myorigin = $mydomain ← 追加
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on. By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
↓
inet_interfaces = all ← 变更(可以收外网邮件)
# The mydestination parameter specifies the list of domains that this# machine considers itself the final destination for.
#
# These domains are routed to the delivery agent specified with the
# local_transport parameter setting. By default, that is the UNIX
# compatible delivery agent that lookups all recipients in /etc/passwd
# and /etc/aliases or their equivalent.
#
# The default is $myhostname + localhost.$mydomain. On a mail domain
# gateway, you should also include $mydomain.
#
# Do not specify the names of virtual domains - those domains are
# specified elsewhere (see VIRTUAL_README).
#
# Do not specify the names of domains that this machine is backup MX
# host for. Specify those names via the relay_domains settings for
# the SMTP server, or use permit_mx_backup if you are lazy (see
# STANDARD_CONFIGURATION_README).
#
# The local machine is always the final destination for mail addressed
# to user@[the.net.work.address] of an interface that the mail system
# receives mail on (see the inet_interfaces parameter).
#
# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
mydestination = $myhostname, localhost.$mydomain, localhost
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ← 变更
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
#home_mailbox = Maildir/
home_mailbox = Maildir/ ← 追加(邮件箱Maildir形式)
# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server's greeting banner. Some people like to see
# the mail version advertised. By default, Postfix shows no version.
#
# You MUST specify $myhostname at the start of the text. That is an
# RFC requirement. Postfix itself does not care.
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown ← 追加(隐藏邮件服务器所使用的软件名)
下面到结尾都是追加的(SMTP-Auth设定)
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
message_size_limit = 10485760 ← 追加(限制邮件大小10MB=10*1024*1024)
2.SMTP-Auth设定
[root@centos ~]# /etc/rc.d/init.d/saslauthd start ← saslauthd启动
saslauthd 启动中: [ OK ]
[root@centos ~]# chkconfig saslauthd on ← saslauthd自动启动设定
[root@centos ~]# chkconfig --list saslauthd ← saslauthd自动启动确认
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@centos ~]# vi /usr/lib/sasl2/smtpd.conf ← 修改SMTP-Auth认证文件
pwcheck_method: saslauthd
↓
pwcheck_method: auxprop ← 变更
3.设置Maildir形式的邮件箱
[root@centos ~]# mkdir -p /etc/skel/Maildir/{new,cur,tmp}
[root@centos ~]# chmod -R 700 /etc/skel/Maildir/
1.安装好postfix
#vi /etc/postfix/main.cf
# INTERNET HOST AND DOMAIN NAMES
#
# The myhostname parameter specifies the internet hostname of this
# mail system. The default is to use the fully-qualified domain name
# from gethostname(). $myhostname is used as a default value for many
# other configuration parameters.
#
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = mail.xxxx.com ← 追加
# The mydomain parameter specifies the local internet domain name.
# The default is to use $myhostname minus the first component.
# $mydomain is used as a default value for many other configuration
# parameters.
#
#mydomain = domain.tld
mydomain = xxxx.com ← 追加(域名指定)
# SENDING MAIL
#
# The myorigin parameter specifies the domain that locally-posted
# mail appears to come from. The default is to append $myhostname,
# which is fine for small sites. If you run a domain with multiple
# machines, you should (1) change this to $mydomain and (2) set up
# a domain-wide alias database that aliases each user to
# user@that.users.mailhost.
#
# For the sake of consistency between sender and recipient addresses,
# myorigin also specifies the default domain name that is appended
# to recipient addresses that have no @domain part.
#
#myorigin = $myhostname
#myorigin = $mydomain
myorigin = $mydomain ← 追加
# The inet_interfaces parameter specifies the network interface
# addresses that this mail system receives mail on. By default,
# the software claims all active interfaces on the machine. The
# parameter also controls delivery of mail to user@[ip.address].
#
# See also the proxy_interfaces parameter, for network addresses that
# are forwarded to us via a proxy or network address translator.
#
# Note: you need to stop/start Postfix when this parameter changes.
#
#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
↓
inet_interfaces = all ← 变更(可以收外网邮件)
# The mydestination parameter specifies the list of domains that this# machine considers itself the final destination for.
#
# These domains are routed to the delivery agent specified with the
# local_transport parameter setting. By default, that is the UNIX
# compatible delivery agent that lookups all recipients in /etc/passwd
# and /etc/aliases or their equivalent.
#
# The default is $myhostname + localhost.$mydomain. On a mail domain
# gateway, you should also include $mydomain.
#
# Do not specify the names of virtual domains - those domains are
# specified elsewhere (see VIRTUAL_README).
#
# Do not specify the names of domains that this machine is backup MX
# host for. Specify those names via the relay_domains settings for
# the SMTP server, or use permit_mx_backup if you are lazy (see
# STANDARD_CONFIGURATION_README).
#
# The local machine is always the final destination for mail addressed
# to user@[the.net.work.address] of an interface that the mail system
# receives mail on (see the inet_interfaces parameter).
#
# Specify a list of host or domain names, /file/name or type:table
# patterns, separated by commas and/or whitespace. A /file/name
# pattern is replaced by its contents; a type:table is matched when
# a name matches a lookup key (the right-hand side is ignored).
# Continue long lines by starting the next line with whitespace.
#
# See also below, section "REJECTING MAIL FOR UNKNOWN LOCAL USERS".
#
mydestination = $myhostname, localhost.$mydomain, localhost
↓
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain ← 变更
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
# mail.$mydomain, www.$mydomain, ftp.$mydomain
# DELIVERY TO MAILBOX
#
# The home_mailbox parameter specifies the optional pathname of a
# mailbox file relative to a user's home directory. The default
# mailbox file is /var/spool/mail/user or /var/mail/user. Specify
# "Maildir/" for qmail-style delivery (the / is required).
#
#home_mailbox = Mailbox
#home_mailbox = Maildir/
home_mailbox = Maildir/ ← 追加(邮件箱Maildir形式)
# SHOW SOFTWARE VERSION OR NOT
#
# The smtpd_banner parameter specifies the text that follows the 220
# code in the SMTP server's greeting banner. Some people like to see
# the mail version advertised. By default, Postfix shows no version.
#
# You MUST specify $myhostname at the start of the text. That is an
# RFC requirement. Postfix itself does not care.
#
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown ← 追加(隐藏邮件服务器所使用的软件名)
下面到结尾都是追加的(SMTP-Auth设定)
smtpd_sasl_auth_enable = yes
smtpd_sasl_local_domain = $myhostname
smtpd_recipient_restrictions =
permit_mynetworks
permit_sasl_authenticated
reject_unauth_destination
message_size_limit = 10485760 ← 追加(限制邮件大小10MB=10*1024*1024)
2.SMTP-Auth设定
[root@centos ~]# /etc/rc.d/init.d/saslauthd start ← saslauthd启动
saslauthd 启动中: [ OK ]
[root@centos ~]# chkconfig saslauthd on ← saslauthd自动启动设定
[root@centos ~]# chkconfig --list saslauthd ← saslauthd自动启动确认
saslauthd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@centos ~]# vi /usr/lib/sasl2/smtpd.conf ← 修改SMTP-Auth认证文件
pwcheck_method: saslauthd
↓
pwcheck_method: auxprop ← 变更
3.设置Maildir形式的邮件箱
[root@centos ~]# mkdir -p /etc/skel/Maildir/{new,cur,tmp}
[root@centos ~]# chmod -R 700 /etc/skel/Maildir/
|
4.如果系统默认启动了sendmail或者其他邮件软件 把它停了 并取消自动启动 我的情况是sendmail
[root@centos ~]# /etc/rc.d/init.d/sendmail stop
[root@centos ~]# chkconfig sendmail off
[root@centos ~]# chkconfig --list sendmail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
5.邮件服务器切换
[root@centos ~]# alternatives --config mta ← 邮件服务器切换 (会出现下面)
choice command
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
:2 ← 选择Postfix的编号 按enter
6.启动Postfix
[root@centos ~]# /etc/rc.d/init.d/postfix start
Starting postfix: [ OK ]
[root@centos ~]# chkconfig postfix on
[root@centos ~]# chkconfig --list postfix
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
7.安装dovecot (centos用yum可以安装 Ubuntu应该是apt-get)
[root@centos ~]# vi /etc/dovecot.conf ← 修改Dovecot设定文件
# Protocols we want to be serving:
# imap imaps pop3 pop3s
#protocols = imap imaps
protocols = imap imaps pop3 pop3s ← 追加
# Location for users' mailboxes. This is the same as the old default_mail_env
# setting. The default is empty, which means that Dovecot tries to find the
# mailboxes automatically. This won't work if the user doesn't have any mail
# yet, so you should explicitly tell Dovecot the full location.
#
# If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn't enough. You'll also need to tell Dovecot where the other mailboxes are
# and where Dovecot can place its index files. This is called the "root mail
# directory", and it must be the first path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if there's no domain
# %h - home directory
#
# See doc/variables.txt for full list. Some examples:
#
# mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# http://wiki.dovecot.org/MailLocation
#
#mail_location =
mail_location = maildir:~/Maildir ← 追加
# Default MAIL environment to use when it's not set. By leaving this empty
# dovecot tries to do some automatic detection as described in
# doc/mail-storages.txt. There's a few special variables you can use:
#
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if user there's no domain
# %h - home directory
#
# You can also limit a width of string by giving the number of max. characters
# after the '%' character. For example %1u gives the first character of
# username. Some examples:
#
# default_mail_env = maildir:/var/mail/%1u/%u/Maildir
# default_mail_env = mbox:~/mail/:INBOX=/var/mail/%u
# default_mail_env = mbox:/var/mail/%d/%n/:INDEX=/var/indexes/%d/%n
#
#default_mail_env =
default_mail_env = maildir:~/Maildir ← 追加
# ':' separated list of directories under which chrooting is allowed for mail
# processes (ie. /var/mail will allow chrooting to /var/mail/foo/bar too).
# This setting doesn't affect login_chroot or auth_chroot variables.
# WARNING: Never add directories here which local users can modify, that
# may lead to root exploit. Usually this should be done only if you don't
# allow shell access for users. See doc/configuration.txt for more information.
#valid_chroot_dirs =
valid_chroot_dirs = /home ← 追加※用OpenSSH进行Chroot的情况下才设
[root@centos ~]# /etc/rc.d/init.d/dovecot start
Dovecot Imap启动中: [ OK ]
[root@centos ~]# chkconfig dovecot on
[root@centos ~]# chkconfig --list dovecot
dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off
8.邮件用户追加(以centos为例)
[root@centos ~]# useradd -s /sbin/nologin centos ← 用户追加
[root@centos ~]# passwd centos ← 密码设定
Changing password for user centos.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
如果想把SMTP-Auth用的用户名和密码弄的跟系统用户名和密码不同的话 才用到下面4步
[root@centos ~]# echo "密码" | saslpasswd2 -p -u 域名 -c centos
[root@centos ~]# sasldblistusers2 ← SMTP-Auth用用户名密码确认
centos@域名: userPassword
[root@centos ~]# chgrp postfix /etc/sasldb2 ← 把/etc/sasldb2的所有group变成postfix
想删除SMTP-Auth用用户名密码确认
[root@centos ~]# saslpasswd2 -d centos -u 域名
好了 用Windows的outlook express邮件收发软件测试一下吧
到这儿就大概设定完了 如果屏蔽垃圾邮件 就得你自己努力了
[root@centos ~]# /etc/rc.d/init.d/sendmail stop
[root@centos ~]# chkconfig sendmail off
[root@centos ~]# chkconfig --list sendmail
sendmail 0:off 1:off 2:off 3:off 4:off 5:off 6:off
5.邮件服务器切换
[root@centos ~]# alternatives --config mta ← 邮件服务器切换 (会出现下面)
choice command
-----------------------------------------------
*+ 1 /usr/sbin/sendmail.sendmail
2 /usr/sbin/sendmail.postfix
:2 ← 选择Postfix的编号 按enter
6.启动Postfix
[root@centos ~]# /etc/rc.d/init.d/postfix start
Starting postfix: [ OK ]
[root@centos ~]# chkconfig postfix on
[root@centos ~]# chkconfig --list postfix
postfix 0:off 1:off 2:on 3:on 4:on 5:on 6:off
7.安装dovecot (centos用yum可以安装 Ubuntu应该是apt-get)
[root@centos ~]# vi /etc/dovecot.conf ← 修改Dovecot设定文件
# Protocols we want to be serving:
# imap imaps pop3 pop3s
#protocols = imap imaps
protocols = imap imaps pop3 pop3s ← 追加
# Location for users' mailboxes. This is the same as the old default_mail_env
# setting. The default is empty, which means that Dovecot tries to find the
# mailboxes automatically. This won't work if the user doesn't have any mail
# yet, so you should explicitly tell Dovecot the full location.
#
# If you're using mbox, giving a path to the INBOX file (eg. /var/mail/%u)
# isn't enough. You'll also need to tell Dovecot where the other mailboxes are
# and where Dovecot can place its index files. This is called the "root mail
# directory", and it must be the first path given in the mail_location setting.
#
# There are a few special variables you can use, eg.:
#
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if there's no domain
# %h - home directory
#
# See doc/variables.txt for full list. Some examples:
#
# mail_location = maildir:~/Maildir
# mail_location = mbox:~/mail:INBOX=/var/mail/%u
# mail_location = mbox:/var/mail/%d/%1n/%n:INDEX=/var/indexes/%d/%1n/%n
#
# http://wiki.dovecot.org/MailLocation
#
#mail_location =
mail_location = maildir:~/Maildir ← 追加
# Default MAIL environment to use when it's not set. By leaving this empty
# dovecot tries to do some automatic detection as described in
# doc/mail-storages.txt. There's a few special variables you can use:
#
# %u - username
# %n - user part in user@domain, same as %u if there's no domain
# %d - domain part in user@domain, empty if user there's no domain
# %h - home directory
#
# You can also limit a width of string by giving the number of max. characters
# after the '%' character. For example %1u gives the first character of
# username. Some examples:
#
# default_mail_env = maildir:/var/mail/%1u/%u/Maildir
# default_mail_env = mbox:~/mail/:INBOX=/var/mail/%u
# default_mail_env = mbox:/var/mail/%d/%n/:INDEX=/var/indexes/%d/%n
#
#default_mail_env =
default_mail_env = maildir:~/Maildir ← 追加
# ':' separated list of directories under which chrooting is allowed for mail
# processes (ie. /var/mail will allow chrooting to /var/mail/foo/bar too).
# This setting doesn't affect login_chroot or auth_chroot variables.
# WARNING: Never add directories here which local users can modify, that
# may lead to root exploit. Usually this should be done only if you don't
# allow shell access for users. See doc/configuration.txt for more information.
#valid_chroot_dirs =
valid_chroot_dirs = /home ← 追加※用OpenSSH进行Chroot的情况下才设
[root@centos ~]# /etc/rc.d/init.d/dovecot start
Dovecot Imap启动中: [ OK ]
[root@centos ~]# chkconfig dovecot on
[root@centos ~]# chkconfig --list dovecot
dovecot 0:off 1:off 2:on 3:on 4:on 5:on 6:off
8.邮件用户追加(以centos为例)
[root@centos ~]# useradd -s /sbin/nologin centos ← 用户追加
[root@centos ~]# passwd centos ← 密码设定
Changing password for user centos.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
如果想把SMTP-Auth用的用户名和密码弄的跟系统用户名和密码不同的话 才用到下面4步
[root@centos ~]# echo "密码" | saslpasswd2 -p -u 域名 -c centos
[root@centos ~]# sasldblistusers2 ← SMTP-Auth用用户名密码确认
centos@域名: userPassword
[root@centos ~]# chgrp postfix /etc/sasldb2 ← 把/etc/sasldb2的所有group变成postfix
想删除SMTP-Auth用用户名密码确认
[root@centos ~]# saslpasswd2 -d centos -u 域名
好了 用Windows的outlook express邮件收发软件测试一下吧
到这儿就大概设定完了 如果屏蔽垃圾邮件 就得你自己努力了
|
学习楼上大哥的。收藏了。