Posts Tagged ‘ postfix ’

注:本方法使用了postfix做mta, 使用系统帐号(可无loginshell,无home使其无法登陆),通过sasl库来验证snmp和pop/imap. postfix收到的本地邮件,通过lmtp传送给cyrus-imap,由cyrus-imap存到自己格式的邮件,供mua来收信。本方法构建简单快捷,适合帐号数量少用户使用。

  1. 设置域名
    由于域名生效时间比较长,先设置域名。比如我我想设置的邮件对外的地址是username@manew.org,我的域名是manew.org,邮件主机是mail.manew.org,已经设置了A记录,则现在需要添加MX记录manew.org,value为mail.manew.org
  2. 安装软件包
    通过光盘上的包,或yum安装需要的包:
    postfix-2.3.3-2
    cyrus-imapd-2.3.7-1.1.el5
    cyrus-sasl-2.1.22-4
    cyrus-sasl-md5-2.1.22-4
    cyrus-imapd-utils-2.3.7-1.1.el5
    cyrus-sasl-plain-2.1.22-4
    cyrus-imapd-perl-2.3.7-1.1.el5
    cyrus-sasl-lib-2.1.22-4
  3. 设置smtpd的sasl认证
    sasl的smtp认证配置文件位于:/usr/lib/sasl2/smtpd.conf
    内容修改为如下:[felix ~]$ cat /usr/lib/sasl2/smtpd.conf
    pwcheck_method: saslauthd
  4. 设置postfix
    postfix的rpm安装后,配置文件在/etc/postfix下. main.cf是他的最主要的配置文件,我们修改main.cf
    修改或添加如下内容:
    #域名信息
    #监听网口
    inet_interfaces = all
    #邮件主机名myhostname = mail.manew.org
    #域件域
    mydomain = manew.org
    #当发信人没有填写标准完整名时,postfix自动补齐
    myorigin = $mydomain
    #何样的邮件postfix收下做为本地邮件
    mydestination = $mydomain, localhost, localhost.localdomain
    #收哪些邮件,在recp_sender里不存在的邮件,postfix将拒收
    local_recipient_maps = hash:/etc/postfix/recp_sender
    #lmtp sock文件位置(参考/etc/cyrus.conf)
    mailbox_transport = lmtp:unix:/var/lib/imap/socket/lmtp
    ### sasl auth
    smtpd_sasl_auth_enable = yes
    broken_sasl_auth_clients = yes
    smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
    smtpd_sasl_local_domain = $myhostname
    smtpd_sender_login_maps = hash:/etc/postfix/recp_sender
    smtpd_sasl_security_options = noanonymous文件recp_sender内容为邮件帐号与系统帐号名的对应关系:[felix@mail postfix]$ cat recp_sender
    bar@manew.org   bar
  5. 设置imap
    修改cyrus-imapd的配置文件/etc/imapd.conf[felix@mail postfix]$ cat /etc/imapd.conf
    configdirectory: /var/lib/imap
    partition-default: /var/spool/imap
    admins: cyrus
    sievedir: /var/lib/imap/sieve
    sendmail: /usr/sbin/sendmail
    hashimapspool: true
    sasl_pwcheck_method: saslauthd
  6. 启动服务并测试
    [felix@mail postfix]$ service postfix start
    [felix@mail postfix]$ service cyrus-imapd start
    [felix@mail postfix]$ service saslauthd start
  7. 创建用户名和邮件
    生成邮件系统管理员密码:
    [felix@mail postfix]$ passwd cyrus
    Changing password for user cyrus.
    New UNIX password:[输入密码]
    Retype new UNIX password:[输入密码]
    passwd: all authentication tokens updated successfully.添加一个邮件帐号:
    [felix@mail postfix]$ useradd foo -M -s /sbin/nologin
    [felix@mail postfix]$ passwd foo
    Changing password for user foo.
    New UNIX password:[输入密码]
    Retype new UNIX password:[输入密码]
    passwd: all authentication tokens updated successfully.
    [felix@mail postfix]$ cyradm –user cyrus localhost
    IMAP Password:[输入密码]
    localhost.localdomain> cm user.foo
    localhost.localdomain> quit
    [felix@mail postfix]$ echo ‘foo@manew.org    foo’ >> /etc/postfix/recp_sender
    [felix@mail postfix]$ postmap /etc/postfix/recp_sender
  8. 开机自动运行
    [felix@mail postfix]$ chkconfig –level 345 saslauthd on
    [felix@mail postfix]$ chkconfig –level 345 postfix on
    [felix@mail postfix]$ chkconfig –level 345 cyrus-imapd on
  9. 现在打一个邮件客户端,并测试一下
    邮件名填foo@manew.org,smtpd需要验证,smtp和pop3地址都填mail.manew.org,用户名为foo,密码为foo的系统密码。
    ok?