2007-11-30

[UNIX]sendmail as client with smtp authentication

以前,在學校的時候,都會記得把自己架設的 mail server 加上 sendmail authenticate,可是從來沒想過,如果有一天,在自己的 ISP 下,你必須要認證才可以透過 SMTP Server 寄信的時候,那麼 sendmail 是否有辦法作為其他 SMTP 的 Client 呢?


答案是可以的,設定如下:




  • Change user as root

  • $ su - root

  • Create SMTP Client Authentication Information

  • # cd /etc/mail (如有不同請自行修正啦)
    # mkdir auth
    # chmod 700 auth
    # vim client-info
    AuthInfo:mail-relay.isp.net "U:帳號" "P:密碼"
    # makemap hash client-info.db < client-info
    # chmod 600 client-info*
    # cd ..

  • 修正 sendmail.mc ,加入以下內容


  • define(`SMART_HOST',`mail-relay.isp.net')dnl
    define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
    FEATURE(`authinfo',`hash -o /etc/mail/auth/client-info')dnl

  • 重新產生 sendmail.cf,重跑 sendmail

  • FreeBSD
    # cd /etc/mail
    # make cf
    # mv sendmail.cf sendmail.cf.old
    # mv `hostname`.sendmail.cf sendmail.cf
    # make restart

    Linux
    # cd /etc/mail
    # mv sendmail.cf sendmail.cf.old
    # m4 sendmail.mc > sendmail.cf
    # kill -1 `head -1 /var/run/sendmail.pid`