さくらのVPSの設定 - メールサーバーの構築



 VPS  Postfix  Dovecot 

使


Postfix 2.6.6

Dovecot 2.0.9




$ postconf mail_version
mail_version = 2.6.6
$ dovecot --version
2.0.9

Dovecot 12




(一) Unix 

(二) SSL + SMTP AUTH 

(三)SMTP AUTH 使 Dovecot 


 /var/log/maillog warning 


 localhost.localdomain spamhaus.org  Windows Live Hotmail
/etc/sysconfig/network  HOSTNAME=localhost.localdomain  www9999xx.sakura.ne.jp 
HOSTNAME=www9999xx.sakura.ne.jp

 virtual_mailbox_domains  mydestination 


$ reboot

spamhaus.org  hotmail 


550 OU-001 (SNT0-MC4-F25) Unfortunately, messages from xxx.xxx.xxx.xxx weren't sent.





hotmail550 OU-001


yum cyrus-sasl-md5  SMTP AUTH  CRAM-MD5 
$ yum install postfix dovecot cyrus-sasl-md5

sendmail 使 MTA  postfix   VPS  sendmail 
$ /etc/init.d/sendmail stop
$ chkconfig sendmail off
$ alternatives --config mta

There are 2 programs which provide 'mta'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/sbin/sendmail.sendmail
   2           /usr/sbin/sendmail.postfix

Enter to keep the current selection[+], or type selection number: 2

 postfix 
$ /etc/init.d/postfix start
$ chkconfig postfix on

 sendmail  root 
$ sendmail root
From: root
To: root
Subject: test

test
.

 mail 
$ mail
Heirloom Mail version 12.4 7/29/08.  Type ? for help.
"/var/spool/mail/root": 1 messages 1 unread
>N 1 root@www9999ue.sakur  Wed May 16 12:30  14/473   "test"
&q

/var/log/maillog 




 Unix   vmail UID/GID  10000   /var/mail/virtual   /sbin/nologin 
$ groupadd -g 10000 vmail
$ useradd -u 10000 -g 10000 -d /var/mail/virtual -r -s /sbin/nologin vmail
$ mkdir /var/mail/virtual
$ chown vmail:vmail /var/mail/virtual
$ chmod 700 /var/mail/virtual

使


 Unix  /etc/dovecot/passwd  使

/etc/dovecot/passwd   doveadm pw 使Dovecot  dovecotpw 使
$ doveadm pw
Enter new password:
Retype new password:
{CRAM-MD5}836e14f966d9af5b2c7a1a07a45292b4b0a1805bc050343491cbc18f0539962f

 /etc/dovecot/passwd   ":"   Dovecot 使[]
test@example.com:{CRAM-MD5}836e14f966d9af5b2c7a1a07a45292b4b0a1805bc050343491cbc18f0539962f
test2@example.com:{CRAM-MD5}836e14f966d9af5b2c7a1a07a45292b4b0a1805bc050343491cbc18f0539962f

test@example.com  test2@example.com  使 example.com 
 example.com 使

/etc/postfix/vmailbox 
test@example.com    example.com/test/Maildir/
test2@example.com   example.com/test2/Maildir/

 postmap 
$ postmap /etc/postfix/vmailbox


.forward /etc/postfix/virtual  ()  []
(受信メールアドレス)  (転送先1), (転送先2), ...

()


$ postmap /etc/postfix/virtual

SSL 


openssl  Common Name  DNS MX ( (.der) )  使 *.example.com 
$ cd /etc/pki/tls/certs
$ openssl req -new -x509 -nodes -days 365 -out mail.crt -keyout mail.key
Generating a 2048 bit RSA private key
...+++
....+++
writing new private key to 'mail.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:
State or Province Name (full name) []:
Locality Name (eg, city) [Default City]:
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:*.example.com
Email Address []:
$ chmod 600 mail.key

 (.der) 
$ openssl x509 -in mail.crt -outform der -out mail.der

Postfix 


 Postfix 


/etc/postfix/main.cf


/etc/postfix/master.cf

使
$ postconf -n




Postfix Documentation []

All main.cf parameters []

master.cf file format []

main.cf 


main.cf 
inet_interfaces = all
smtpd_banner = $myhostname ESMTP unknown

smtpd_client_restrictions =
  reject_rbl_client all.rbl.jp,
  reject_rbl_client bl.spamcop.net

# SASL
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/dovecot-auth
smtpd_sasl_security_options = noanonymous

# TLS
smtpd_tls_security_level = may
smtpd_tls_key_file = /etc/pki/tls/certs/mail.key
smtpd_tls_cert_file = /etc/pki/tls/certs/mail.crt

# Virtual
virtual_mailbox_domains = example.com
virtual_mailbox_base = /var/mail/virtual
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_uid_maps = static:10000
virtual_gid_maps = static:10000
virtual_alias_maps = hash:/etc/postfix/virtual




inet_interfaces [ja]  

smtpd_banner [ja]

smtpd_client_restrictions [ja]


smtpd_sasl_type [ja] Postfix SMTP  Dovecot 使

smtpd_sasl_path [ja] Dovecot 

smtpd_sasl_security_options [ja]


smtpd_tls_security_level [ja] Postfix SMTP  SMTP TLS  STARTTLS 

smtpd_tls_key_file [ja] (PEM )

smtpd_tls_cert_file [ja]


virtual_mailbox_domains [ja]

virtual_mailbox_base [ja] $virtual_mailbox_maps 

virtual_mailbox_maps [ja] $virtual_mailbox_base 

virtual_uid_maps [ja] MTA 使 uid 

virtual_gid_maps [ja] MTA 使 gid 

virtual_alias_maps [ja]

master.cf 


submission 使
submission inet n       -       n       -       -       smtpd
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination




smtpd_tls_security_level [ja] TLS 

smtpd_sasl_auth_enable [ja] Postfix SMTP  SASL 

smtpd_client_restrictions [ja]

smtpd_recipient_restrictions [jp]  SMTP  smtpd_sasl_auth_enable=yes smtpd_recipient_restrictions  permit_sasl_authenticated 


Postfix 
$ /etc/init.d/postfix restart

inet_interfaces  reload  restart 

Dovecot 


Dovecot 
$ dovecot -n | head -1

 VPS  /etc/dovecot/dovecot.conf   /etc/dovecot/conf.d 
$ dovecot -n



Dovecot 


Dovecot Wiki


Dovecot version 1  Main Configuration  Dovecot 2 (2012-05-20 )

 dovecot.conf 沿

dovecot.conf 


 SMTP AUTH  Postfix  smtpd_sasl_path 
# Postfix SMTP Auth
service auth {
  unix_listener /var/spool/postfix/private/dovecot-auth {
    group = postfix
    mode = 0660
    user = postfix
  }
}

 /var/log/maillog 


warning: SASL: Connect to private/dovecot-auth failed: Connection refused
 fatal: no SASL authentication mechanisms

conf.d/10-mail.conf 


 $mail_home 
mail_location = maildir:~/Maildir


conf.d/10-ssl.conf 


 SSL 
ssl_cert = </etc/pki/tls/certs/mail.crt
ssl_key = </etc/pki/tls/certs/mail.key

conf.d/10-auth.conf 



auth_mechanisms = cram-md5 plain login

!include auth-passwdfile.conf.ext
!include auth-static.conf.ext


conf.d/auth-passwdfile.conf.ext 


使
passdb {
  driver = passwd-file
  args = scheme=CRAM-MD5 username_format=%u /etc/dovecot/passwd
}


conf.d/auth-static.conf.ext 


userdb 使 Postfix  virtual_mailbox_base, virtual_mailbox_maps Dovecot  mail_home(home), mail_location 
userdb {
  driver = static
  args = uid=vmail gid=vmail home=/var/mail/virtual/%d/%n
}

: userdb, static, variables

Dovecot 
$ /etc/init.d/dovecot start
$ chkconfig dovecot on

iptables 


使 SMTP(25, 587), POP3(110), POP3s(995), IMAP4(143), IMAP4s(993) 

 /etc/sysconfig/iptables 
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 25 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 110 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 143 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 587 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 993 -j ACCEPT
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 995 -j ACCEPT

iptables 
$ /etc/init.d/iptables restart

DNS 


pop, imap, smtp, mail 使
a * IPアドレス 
mx mail.example.com. 10

IP IP


 (.der)   Thunderbird 

[]  []  []  [] [] [] 


[]  []  .der 


[] 


[] [OK] 





PostfixDovecotVPS

PostfixLinux

POP3sIMAP4sSMTPsover SSL


使

[amazon asin="479811930X" /]
カテゴリー: 記事 タグ: , パーマリンク

40 Responses to さくらのVPSの設定 - メールサーバーの構築

  1. 匿名 のコメント:

    (unknown user: "test")ってなってしまいます

    testで送信(test→gmail)→OK test宛に送信(gmail→test)→NG

    どうなんでしょうか・・・

  2. NORI のコメント:

    /etc/dovecot/passwd ファイルの内容を再度ご確認ください。

    test@your.domain に関する設定が記述されていますか?

  3. 匿名 のコメント:

    /etc/dovecot/passwd内で設定はしていたのですが改行していなかったためでした 改行したらすんなり行きました

    お騒がせしてスミマセン・・・

  4. NORI のコメント:

    なるほど、うまくいって何よりです。

  5. Isao のコメント:

    VPS(Centos6.3 32bit)Centos6.3 64bit
  6. NORI のコメント:

    CentOS ならば 64bit でも基本的には同じ手順で良いと思います。 ただ、デフォルトでインストールされているソフトウェアがさくらの VPS とは異なるはずですので、その点は注意が必要です。 Sendmail の停止などが必要かもしれません。

    > なかなかできません。
    どこがうまくいきませんか?

  7. Isao のコメント:

    SendmailSElinux/var/log/maillogdovecot: pop3-login: Aborted login (no auth attempts)
  8. NORI のコメント:

    POP で接続する時の認証がうまくいっていないようです。 認証に関係ありそうな設定(/etc/dovecot/passwd やメールクライアントも含む)を確認し、それらをわざと変更したときの maillog の内容の変化を参考に対応するのが良いと思います。

    > dovecot: pop3-login: Aborted login (no auth attempts)
    このログだけでは原因の特定が難しいと思いましたので

  9. shotaro kawaguchi のコメント:

    こちらの設定では、windows live mail では 認証が通らないようなんですが、なにがまちがっているのでしょうか?

  10. NORI のコメント:

    Windows Live Hotmail へ送るためには、最近この記事に追加した「ホスト名の設定」を行う必要があります。一番上の方に書いてあるので参考にしてください。 また、既に spamhaus.org のリストに shotaro kawaguchi さんのドメインが登録されていると考えられます。その場合、リストから消してもらう手続きが必要になります。これは「ホスト名の設定」のところの [参考] のリンク先の記事を参考に行えば良いです。

  11. s_kawa のコメント:

    is not listed in the 


  12. s_kawa のコメント:

    たびたびすみません。 windows live mail の認証方式が APOP か PLAIN とみたのですが、これは関係ありますか?

  13. NORI のコメント:

    少し勘違いしておりました。

    > windows live mail では 認証が通らない…
    とのことですが、何の認証のことでしょうか?

  14. s_kawa のコメント:

    thinderbird  windows live mail  

    調windows live mail  outlook  APOP  PLAIN 
  15. NORI のコメント:

    私のマシンで試してみたところ、確かに Thunderbird では簡単にアカウント追加と送受信ができましたが、Outlook ではうまく設定できませんでした。 Outlook 2010 では、メニューバーの [ファイル] → [情報] → [アカウントの追加] → [自分で電子メールや・・・(手動設定)] → [インターネット電子メール] → [詳細設定] → [詳細設定]タブ の辺りで暗号化の種類などを選択できましたが、どうも「アカウント設定のテスト」がうまくいきませんでした。

    暗号化接続の種類として SSH や TLS も選択できましたが、軽く調べただけでは正しい設定方法はわかりませんでした。

  16. s_kawa のコメント:





    http://satospo.sakura.ne.jp/blog_archives/tech/tool/windows_mail.html



    PlainSSL

    調

    調
  17. ピンバック: Hello world! | KHe7@WWW

  18. shawn のコメント:

    VPS VPS CentOS 6 x86_64 

    root putty

    error reading input: Input/output error


  19. NORI のコメント:

    putty


     Putty 


    • 「ホスト名の設定」がきちんと出来ているか
      (設定内容、および、設定変更後の再起動)
    • 再現性の有無
    • /var/log/maillog の内容
  20. shawn のコメント:



    putty





    reboot

    nothing to do

    /etc/init.d/postfix start

    chkconfig postfix on






     HOSTNAME=www9999xx.sakura.ne.jp 


     putty

    /var/log/maillog 
     
    Apr 24 15:00:00 www9999xx postfix/sendmail[1446]: fatal: root(0): error reading input: Input/output error





  21. NORI のコメント:

    PuTTY が止まってしまうという現象についてですが、これは接続が断たれることにより止まっているのでしょうか?

    入力待ちなど、他の原因で止まっているということはありませんか?
    Ctrl + Z や Ctrl + C などにも反応しないのでしょうか?

  22. shawn のコメント:



    Ctrl + Z使 sendmail 使 .


  23. NORI のコメント:

    原因がわかって良かったです!

  24. 匿名 のコメント:





    DNS 
     a * IP
     mx mail.example.com. 10




    http://muumuu-domain.com/?mode=guide&state=custom_setup


    5[2] 



  25. NORI のコメント:



     ValueDomain ValueDomain  DNS
  26. 匿名 のコメント:





    postmap /etc/postfix/vmailbox  conf.d/auth-passwdfile.conf.ext  passdb {  driver = passwd-file  args = scheme=CRAM-MD5 username_format=%u /etc/dovecot/passwd }

    Thunderbird

    May 25 17:55:52 [] postfix/smtpd[1745]: fatal: open database /etc/postfix/virtual.db: No such file or directory May 25 17:55:52 [] dovecot: auth: Error: passwd-file /etc/dovecot/users: Can't open file: No such file or directory May 25 17:55:52 [] dovecot: master: Error: service(auth): command startup failed, throttling May 25 17:55:52 [] dovecot: log: Error: service(auth): child 1746 returned error 89 (Fatal failure) May 25 17:55:53 [] postfix/master[1655]: warning: process /usr/libexec/postfix/smtpd pid 1745 exit status 1 May 25 17:55:53 [] postfix/master[1655]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling May 25 17:56:04 [] dovecot: imap-login: Disconnected (no auth attempts): rip=[IP], lip=[VPSIP] May 25 17:56:04 [] dovecot: imap-login: Disconnected (no auth attempts): rip=[IP], lip=[VPSIP] May 25 17:56:04 [] dovecot: imap-login: Disconnected (no auth attempts): rip=[IP], lip=[VPSIP] May 25 17:56:04 [] dovecot: imap-login: Disconnected (no auth attempts): rip=[IP], lip=[VPSIP] May 25 17:56:04 [] dovecot: imap-login: Disconnected (no auth attempts): rip=[IP], lip=[VPSIP] May 25 17:56:04 [] dovecot: imap-login: Disconnected (no auth attempts): rip=[IP], lip=[VPSIP] May 25 17:56:27 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1753, input bytes=0 May 25 17:56:27 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1754, input bytes=0 May 25 17:56:27 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1751, input bytes=0 May 25 17:56:27 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1747, input bytes=0 May 25 17:56:27 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1749, input bytes=0 May 25 17:56:27 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1744, input bytes=0 May 25 17:56:52 [] dovecot: auth: Error: passwd-file /etc/dovecot/users: Can't open file: No such file or directory May 25 17:56:52 [] dovecot: log: Error: service(auth): child 1758 returned error 89 (Fatal failure) May 25 17:56:52 [] dovecot: master: Error: service(auth): command startup failed, throttling May 25 17:56:53 [] postfix/smtpd[1759]: fatal: open database /etc/postfix/virtual.db: No such file or directory May 25 17:56:54 [] postfix/master[1655]: warning: process /usr/libexec/postfix/smtpd pid 1759 exit status 1 May 25 17:56:54 [] postfix/master[1655]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling May 25 17:57:22 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1751, input bytes=0 May 25 17:57:23 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1749, input bytes=0 May 25 17:57:23 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1744, input bytes=0 May 25 17:57:23 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1753, input bytes=0 May 25 17:57:23 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1754, input bytes=0 May 25 17:57:23 [] dovecot: pop3-login: Error: Timeout waiting for handshake from auth server. my pid=1747, input bytes=0

    May 25 18:01:58 [] postfix/smtpd[1774]: fatal: open database /etc/postfix/virtual.db: No such file or directory May 25 18:01:59 [] postfix/master[1655]: warning: process /usr/libexec/postfix/smtpd pid 1774 exit status 1 May 25 18:01:59 [] postfix/master[1655]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling May 25 18:02:59 [] postfix/smtpd[1777]: fatal: open database /etc/postfix/virtual.db: No such file or directory May 25 18:03:00 [] postfix/master[1655]: warning: process /usr/libexec/postfix/smtpd pid 1777 exit status 1 May 25 18:03:00 [] postfix/master[1655]: warning: /usr/libexec/postfix/smtpd: bad command startup -- throttling May 25 18:04:00 [] postfix/smtpd[1786]: fatal: open database /etc/postfix/virtual.db: No such file or directory May 25 18:04:01 [] postfix/master[1655]: warning: process /usr/libexec/postfix/smtpd pid 1786 exit status 1 ...


  27. NORI のコメント:
    postmap /etc/postfix/virtual

    を実行していかいからではないでしょうか?

  28. 匿名 のコメント:

    同じエラーが出たので調べたところ、 Dovecotの設定でauth-passwdfile.conf.extのuserdbのセクションも上のpassdbと同じ設定に変えてあげないといけないようでした。

  29. めぐみ のコメント:



    /var/log/maillog

    postfix/smtpd[9469]: NOQUEUE: reject: RCPT from mail-pa0-f48.google.com[IP]: 55 4 5.7.1 <>: Relay access denied; from=



    saslauthd Off

    /etc/rc.d/init.d/saslauthd start

    chkconfig saslauthd on

    postfix

    main.cfsmtpd_client_restrictions 




  30. NORI のコメント:

    main.cf の virtual_mailbox_domains の設定が、<作ったメールアドレス> のドメインと同じになっていることを確認してください。

  31. めぐみ のコメント:

    NORIさん、お返事ありがとうございます!

    メールアドレスは、 「xxxx@mail.ドメイン」にしたのですが、

    virtual_mailbox_domains =ドメイン から
    virtual_mailbox_domains =mail.ドメイン

    に変更して、

    postmap /etc/postfix/vmailbox
    /etc/init.d/postfix restart




  32. NORI のコメント:

    うまくいってよかったです!!

  33. トド黒 のコメント:

    VPS SSL使 SSL ()

    maillog

    dovecot: pop3-login: Fatal: Couldn't parse private ssl_key: error:0906D06C:PEM routines:PEM_read_bio:no start line: Expecting: ANY PRIVATE KEY

    ssl
  34. NORI のコメント:

    dovecot の conf.d/10-ssl.conf の設定があやしいです。 このファイルで SSL/TLS の設定をしています。

    ssl = no

    と設定したらどうでしょうか?

  35. トド黒 のコメント:

     10-ssl.confssl = noDisconnected:Auth proccess broken10-auth.conf!include auth-system.conf.ext 
  36. トド黒 のコメント:

    10-auth.conf!include auth-system.conf.ext
  37. NORI のコメント:

    すみません、それはちょっとわかりません。

    まずは /var/log/maillog を見て、warning などが無いか確認すると良いと思います。

コメントを残す