星期五, 3月 02, 2012

「archLinux」 Postfix 使用 Gmail smtp

最近需要用到 MailServer ,以前也沒有這個經驗,
純粹是PHP smpt 寄信速度的問題,最後選擇了 postfix。
文章參考
  1. http://sherlock.heroku.com/blog/2012/02/03/setting-up-postfix-to-use-gmail-as-an-smtp-relay-host-in-archlinux/ 
  2. archLinux WIki Postfix
「安裝 postfix」

    #pacman -S postfix

「設定」在 /etc/postfix/main.cf   加入

    # 設定 gmail
    relayhost = [smtp.gmail.com]:587

    # 啟用 tls 認證
    smtp_use_tls=yes

    # use sasl when authenticating to foreign SMTP servers
    smtp_sasl_auth_enable = yes

    # 設定密碼路徑
    smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd

    # list of CAs to trust when verifying server certificate
    smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

    # eliminates default security options which are incompatible with gmail
    smtp_sasl_security_options =

 「建立」在 /etc/postfix/sasl_passwd  (即密碼檔案路徑)

     [smtp.gmail.com]:587  username:password

 「執行」建立資料庫檔案

    # postmap /etc/postfix/sasl_passwd

 「啟動服務」

    # rc.d start postfix

 「CodeIgniter」 使用 Email 類別

    $this->load->library('email');

    $config['protocol'] = 'sendmail';

    $config['mailpath'] = '/usr/sbin/sendmail';

    $config['charset'] = 'UTF-8';

    $this->email->initialize($config);