1. 程式人生 > >centos7搭建郵件服務器postfix

centos7搭建郵件服務器postfix

centos7搭建郵件服務器postfi

一、服務端:
  1. 域名解析:
    角色                        記錄類型                        主機記錄                        記錄值
    主域名                    A                                    @                                   104.225.233.249
    郵件域名                A                                     mail                                104.225.233.249
    郵件服務器             MX                                 @                                   mail.dollarphp.com
    反垃圾配置             TXT                                @                                  v=spf1 a mx ~al

    技術分享圖片

  2. 卸載sendmail:
    yum  -y  remove  sendmail
  3. 安裝軟件:
    yum  -y  install  postfix  dovecot  cyrus-sasl-*  mailx
  4. 配置postfix:
    vim /etc/postfix/main.cf
    queue_directory = /var/spool/postfix
    command_directory = /usr/sbin
    daemon_directory = /usr/libexec/postfix
    data_directory = /var/lib/postfix
    mail_owner = postfix
    myhostname = mail.dollarphp.com         #這裏要換成你自己的郵箱服務器
    mydomain = dollarphp.com                #這裏換成你自己的主機服務器
    myorigin = $mydomain
    inet_interfaces = all
    inet_protocols = ipv4
    mydestination = $myhostname, localhost.$mydomain, localhost,$mydomain,mail.$mydomain,www.$mydomain, ftp.$mydomain
    local_recipient_maps =
    unknown_local_recipient_reject_code = 550
    mynetworks = 0.0.0.0/0
    relay_domains = $mydestination
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    home_mailbox = Maildir/
    smtpd_banner = $myhostname ESMTP
    debug_peer_level = 2
    debugger_command =
     PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
     ddd $daemon_directory/$process_name $process_id & sleep 5
    sendmail_path = /usr/sbin/sendmail.postfix
    newaliases_path = /usr/bin/newaliases.postfix
    mailq_path = /usr/bin/mailq.postfix
    setgid_group = postdrop
    html_directory = no
    manpage_directory = /usr/share/man
    sample_directory = /usr/share/doc/postfix-2.10.1/samples
    readme_directory = /usr/share/doc/postfix-2.10.1/README_FILES
    smtpd_sasl_auth_enable = yes
    smtpd_sasl_security_options = noanonymous
    broken_sasl_auth_clients = yes
    smtpd_recipient_restrictions = permit_sasl_authenticated,reject_unauth_destination,permit_mynetworks
    smtpd_client_restrictions = permit_sasl_authenticated
  5. 配置dovecot:
    a. 配置監聽協議:
    vim /etc/dovecot/dovecot.conf
    protocols = imap pop3 lmtp
    listen = *
    dict {
    }
    !include conf.d/*.conf
    !include_try local.conf

    b. 配置登錄方式:
    vim /etc/dovecot/conf.d/10-auth.conf

    disable_plaintext_auth = no
    auth_mechanisms = plain login
    !include auth-system.conf.ext

    c. 配置郵件存儲位置:
    vim /etc/dovecot/conf.d/10-mail.conf

    mail_location = maildir:~/Maildir
    namespace inbox {
    inbox = yes
    }
    first_valid_uid = 1000
    mbox_write_locks = fcntl

    d. 配置ssl(關閉):
    vim /etc/dovecot/conf.d/10-ssl.conf

    ssl = no
    ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
    ssl_key = </etc/pki/dovecot/private/dovecot.pem
  6. 配置sasl2:
    a. 配置系統認證:
    vim /etc/sysconfig/saslauthd
    SOCKETDIR=/run/saslauthd
    MECH=shadow
    FLAGS=

    b. 配置登錄方式(創建新文件):
    vim /usr/lib64/sasl2/smtpd.conf

    pwcheck_method: saslauthd
    mech_list: PLAIN LOGIN
    log_level:3
  7. 添加用戶:
    useradd  dollarphp
    passwd  dollarphp
  8. 啟動服務:
    systemctl  start  dovecot
    systemctl  start  postfix
    systemctl  start  saslauthd
  9. 配置mailx:
    vim /etc/mail.rc
    set hold
    set append
    set ask
    set crt
    set dot
    set keep
    set emptybox
    set indentprefix="> "
    set quote
    set sendcharsets=iso-8859-1,utf-8
    set showname
    set showto
    set newmail=nopoll
    set autocollapse
    set markanswered
    ignore received in-reply-to message-id references
    ignore mime-version content-transfer-encoding
    fwdretain subject date from to
    set bsdcompat
    set [email protected]
    set smtp=mail.dollarphp.com
    set smtp-auth-user=adminmail
    set smtp-auth-password=123456
    set smtp-auth=login
  10. 發送郵件:
    echo  "內容"  |  mail  -s  "標題"  [email protected]
    或
    mail  -s  "標題"  [email protected]  <  test.txt

    二、客戶端:

  11. linux(接收):
    a. 安裝telnet:
    yum  -y  install  telnet

    b. 登錄(dovecot的默認端口是110):

    telnet  104.225.233.249  110

    c. 測試:
    技術分享圖片
    d. 命令介紹:

    USER  xxx:輸入用戶名
    PASS  xxx:輸入密碼
    LIST:顯示信箱
    RETR n:打開第n封信

    e. 退出telnet:

    ctl+]
    quit
  12. windows(發送+接收):
    a. 安裝foxmail(官網:http://www.foxmail.com/):
    技術分享圖片
    b. 登錄:
    技術分享圖片
    技術分享圖片
    技術分享圖片
    c. 測試:
    技術分享圖片
    技術分享圖片

centos7搭建郵件服務器postfix