SSMTPを使用してPostfix経由でメールを送信するときの認証エラー

SSMTPを使用してPostfix経由でメールを送信するときの認証エラー

SSMTPを実行しているサーバーAからPostfixを実行しているサーバーBを介してメールを送信しようとしています。 Postfixサーバーは正常に動作しており、しばらく問題なく本番環境にいました。 Dovecotを使用してPostfixを実行します。

私はGmailアカウントを使用してSSMTPからメールを送信できますが、うまくいきますが、メールプロセス全体をよりよく制御したいので、独自のPostfixサーバーを使用したいと思います。

次のログとコードでは、私のパブリックドメインをexample.comに置き換えました。

以下はSSMTPによって生成されたエラーです。

root@N40L:/etc/ssmtp# echo "test" | mailx -vvv -s "test" [email protected]
[<-] 220 h******.stratoserver.net ESMTP Postfix (Debian/GNU)
[->] EHLO example.com
[<-] 250 DSN
[->] AUTH LOGIN
[<-] 535 5.7.8 Error: authentication failed: Invalid authentication mechanism
send-mail: Server didn't like our AUTH LOGIN (535 5.7.8 Error: authentication failed: Invalid authentication mechanism)

私は2台のコンピュータでDebian 8を実行しています。

これは私のssmtp.confです。

[email protected]
mailhub=example.com:465
rewriteDomain=example.com
hostname=example.com
FromLineOverride=YES
UseTLS=YES
[email protected]
AuthPass=correctpassword

SSMTPは時々英数字以外のパスワードを処理できないことを知っているので、パスワードは文字と数字の文字列です。私はMuttを使ってそれをチェックし、それが正しいパスワード、正しいユーザー名、正しいポートであると確信しています。

サフィックス main.cf:

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
append_dot_mydomain = no
readme_directory = no
smtpd_tls_cert_file=/etc/letsencrypt/live/example.com/fullchain.pem
smtpd_tls_key_file=/etc/letsencrypt/live/example.com/privkey.pem
smtpd_use_tls=yes
smtpd_tls_auth_only = yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
myhostname = ********.stratoserver.net
myorigin = /etc/mailname
mydestination = localhost.stratoserver.net, localhost
relayhost =
mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
mailbox_command = procmail -a "$EXTENSION"
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
message_size_limit=20480000
virtual_mailbox_domains = a.bunch.of names.here.and example.com
virtual_mailbox_base = /var/mail/vmail
virtual_mailbox_maps = mysql:/etc/postfix/mysql_virtual_mailbox_maps.cf
virtual_gid_maps = static:5000
virtual_uid_maps = static:5000
virtual_minimum_uid = 5000
virtual_alias_maps = mysql:/etc/postfix/mysql_virtual_alias_maps.cf
virtual_transport = lmtp:unix:private/dovecot-lmtp
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
content_filter = scan:127.0.0.1:10026
receive_override_options = no_address_mappings

LetsEncrypt証明書は正しい名前を表示し、多くの電話(AndroidとiPhone)だけでなく、さまざまなメールクライアントやWebメールにも満足しています。証明書が正しくなったようです。

master.cf、関連性があるかどうかはわかりませんが:

smtp      inet  n       -       -       -       -       smtpd -v
 -o content_filter=spamassassin
submission inet n       -       -       -       -       smtpd
  -o syslog_name=postfix/submission
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_sasl_authenticated,reject
  -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
smtps     inet  n       -       -       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes
pickup    unix  n       -       -       60      1       pickup
cleanup   unix  n       -       -       -       0       cleanup
qmgr      unix  n       -       n       300     1       qmgr
tlsmgr    unix  -       -       -       1000?   1       tlsmgr
rewrite   unix  -       -       -       -       -       trivial-rewrite
bounce    unix  -       -       -       -       0       bounce
defer     unix  -       -       -       -       0       bounce
trace     unix  -       -       -       -       0       bounce
verify    unix  -       -       -       -       1       verify
flush     unix  n       -       -       1000?   0       flush
proxymap  unix  -       -       n       -       -       proxymap
proxywrite unix -       -       n       -       1       proxymap
smtp      unix  -       -       -       -       -       smtp
relay     unix  -       -       -       -       -       smtp
showq     unix  n       -       -       -       -       showq
error     unix  -       -       -       -       -       error
retry     unix  -       -       -       -       -       error
discard   unix  -       -       -       -       -       discard
local     unix  -       n       n       -       -       local
virtual   unix  -       n       n       -       -       virtual
lmtp      unix  -       -       -       -       -       lmtp
anvil     unix  -       -       -       -       1       anvil
scache    unix  -       -       -       -       1       scache
maildrop  unix  -       n       n       -       -       pipe
  flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient}
uucp      unix  -       n       n       -       -       pipe
  flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient)
ifmail    unix  -       n       n       -       -       pipe
  flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient)
bsmtp     unix  -       n       n       -       -       pipe
  flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient
scalemail-backend unix  -       n       n       -       2       pipe
  flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension}
mailman   unix  -       n       n       -       -       pipe
  flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py
  ${nexthop} ${user}
spamassassin unix -     n       n       -       -       pipe
  user=spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail -oi -f ${sender} ${recipient}
scan      unix  -       -       n       -       16      smtp
        -o smtp_send_xforward_command=yes

127.0.0.1:10025 inet  n -       n       -       16      smtpd
        -o content_filter=
        -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
        -o smtpd_helo_restrictions=
        -o smtpd_client_restrictions=
        -o smtpd_sender_restrictions=
        -o smtpd_recipient_restrictions=permit_mynetworks,reject
        -o mynetworks_style=host
        -o smtpd_authorized_xforward_hosts=127.0.0.0/8

Dovecotの関連構成セクション:

# 2.2.13: /etc/dovecot/dovecot.conf
auth_debug = yes
auth_debug_passwords = yes
auth_verbose = yes
mail_debug = yes
mail_plugins = " quota"
mail_privileged_group = vmail
managesieve_notify_capability = mailto
}
passdb {
  args = /etc/dovecot/dovecot-sql.conf.ext
  driver = sql
}
protocols = " imap lmtp sieve"
service auth {
  unix_listener /var/spool/postfix/private/auth {
    group = postfix
    mode = 0666
    user = postfix
  }
}
service imap-login {
  inet_listener imaps {
    port = 993
    ssl = yes
  }
}
service lmtp {
  unix_listener /var/spool/postfix/private/dovecot-lmtp {
    group = postfix
    mode = 0666
    user = postfix
  }
}
ssl = required
ssl_cert = </etc/letsencrypt/live/example.com/fullchain.pem
ssl_key = </etc/letsencrypt//live/example.com/privkey.pem
userdb {
  args = /etc/dovecot/dovecot-sql.conf.ext
  driver = sql
}
verbose_ssl = yes
protocol lmtp {
  mail_plugins = " quota sieve"
  postmaster_address = [email protected]
}

サーバーAからメールを送信しようとして上記のエラーが発生した場合、サーバーBはこれを/var/mail/mail.logに記録します。

Jan 16 10:29:54 postfix/smtps/smtpd[13601]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Jan 16 10:29:54 postfix/smtps/smtpd[13601]: connect from ******.upc-h.chello.nl[62.194.***.***]
Jan 16 10:29:54 dovecot: auth: Debug: auth client connected (pid=0)
Jan 16 10:29:54 postfix/smtps/smtpd[13601]: warning: ******.upc-h.chello.nl[62.194.***.***]: SASL LOGIN authentication failed: Invalid authentication mechanism
Jan 16 10:29:54 postfix/smtps/smtpd[13601]: lost connection after AUTH from ******.upc-h.chello.nl[62.194.***.***]
Jan 16 10:29:54 postfix/smtps/smtpd[13601]: disconnect from ******.upc-h.chello.nl[62.194.***.***]

AuthMechanism=LOGINssmtp.confにor AuthMechanism=CRAM-MD5(SSMTPのマニュアルページによると、これが利用可能な唯一のメカニズムです)を追加した場合も同様であるため、再度削除しました。

インターネットではGmailをSSMTPで使用することに非常にこだわっているので、私はいくつかの実験をしてUseSTARTTLSを試しました。その後、サーバーAでこれが起こります。

send-mail: Cannot open example.com:465
Can't send mail: sendmail process failed with error code 1

...サーバーBにログインしています。

Jan 16 10:46:01 postfix/smtps/smtpd[14047]: warning: dict_nis_init: NIS domain name not set - NIS lookups disabled
Jan 16 10:46:01 postfix/smtps/smtpd[14047]: connect from ******.upc-h.chello.nl[62.194.***.***]
Jan 16 10:46:12 dovecot: imap-login: Debug: SSL: elliptic curve secp384r1 will be used for ECDH and ECDHE key exchanges
Jan 16 10:46:12 dovecot: imap-login: Debug: SSL: elliptic curve secp384r1 will be used for ECDH and ECDHE key exchanges
Jan 16 10:46:12 dovecot: auth: Debug: auth client connected (pid=14049)
Jan 16 10:46:12 dovecot: auth: Debug: client in: AUTH#0111#011PLAIN#011service=imap#011secured#011session=***************AAAAAAAAAAB#011lip=::1#011rip=::1#011lport=143#011rport=60112#011resp=AG40MGxAd*****************QzE3MDE= (previous base64 data may contain sensitive data)
Jan 16 10:46:12 dovecot: auth-worker(14017): Debug: sql([email protected],::1): query: SELECT email as username, pwd AS password FROM addresses WHERE email = '[email protected]'
Jan 16 10:46:12 dovecot: auth: Debug: client passdb out: OK#0111#[email protected]
Jan 16 10:46:12 dovecot: auth: Debug: master in: REQUEST#011154140673#01114049#0111#0114d206d2a85468af9af75b8538aab7485#011session_pid=14050#011request_auth_token
Jan 16 10:46:12 dovecot: auth-worker(14017): Debug: sql([email protected],::1): SELECT 5000 AS uid, 5000 as gid, email, '/var/mail/vmail/example.com/n40l' AS home FROM addresses WHERE email = '[email protected]'
Jan 16 10:46:12 dovecot: auth: Debug: master userdb out: USER#011154140673#[email protected]#011uid=5000#011gid=5000#[email protected]#011home=/var/mail/vmail/example.com/n40l#011auth_token=ff5b12*****************aedf315ac08e
Jan 16 10:46:12 dovecot: imap-login: Login: user=<[email protected]>, method=PLAIN, rip=::1, lip=::1, mpid=14050, secured, session=<0pDTDTNG0AAAAAAAAAAAAAAAAAAAAAAB>
Jan 16 10:46:12 dovecot: imap: Debug: Loading modules from directory: /usr/lib/dovecot/modules
Jan 16 10:46:12 dovecot: imap: Debug: Module loaded: /usr/lib/dovecot/modules/lib10_quota_plugin.so
Jan 16 10:46:12 dovecot: imap: Debug: Module loaded: /usr/lib/dovecot/modules/lib11_imap_quota_plugin.so
Jan 16 10:46:12 dovecot: imap: Debug: Added userdb setting: plugin/[email protected]
Jan 16 10:46:12 dovecot: imap([email protected]): Debug: Effective uid=5000, gid=5000, home=/var/mail/vmail/example.com/n40l
Jan 16 10:46:12 dovecot: imap([email protected]): Debug: Quota root: name=User quota backend=maildir args=
Jan 16 10:46:12 dovecot: imap([email protected]): Debug: Quota rule: root=User quota mailbox=* bytes=10737418240 messages=0
Jan 16 10:46:12 dovecot: imap([email protected]): Debug: Quota rule: root=User quota mailbox=Trash bytes=+104857600 messages=0
Jan 16 10:46:12 dovecot: imap([email protected]): Debug: Quota grace: root=User quota bytes=536870912 (5%)
Jan 16 10:46:12 dovecot: imap([email protected]): Debug: Namespace inbox: type=private, prefix=, sep=, inbox=yes, hidden=no, list=yes, subscriptions=yes location=maildir:/var/mail/vmail/example.com/n40l
Jan 16 10:46:12 dovecot: imap([email protected]): Debug: maildir++: root=/var/mail/vmail/example.com/n40l, index=, indexpvt=, control=, inbox=/var/mail/vmail/example.com/n40l, alt=
Jan 16 10:46:12 dovecot: imap([email protected]): Disconnected: Logged out in=50 out=475

Bサーバーのウェブメールに問題なくログインが可能で、私が使用しているアドレスにメールを送受信できるため、アカウント自体は問題ありません。別のアカウントを試してみましたが、同じエラーが発生しました。

私は迷っています。 SSMTPはPostfix経由でメールを送信できる必要があります。デバッグオプションと詳細オプションの両方を有効にしても問題の原因が見つかりません。どんな助けでも大変感謝します。

ベストアンサー1

root@N40L:/etc/ssmtp# echo "test" | mailx -vvv -s "test" [email protected]
[<-] 220 h******.stratoserver.net ESMTP Postfix (Debian/GNU)
[->] EHLO example.com
[<-] 250 DSN

このコマンドはPostfixに接続してプロファイルをh******.stratoserver.net送信しますEHLO。ただし、受信した応答は、単に250 DSNPostfixが現在の認証を受け入れる意思がないことを示します。認証を受け入れると、応答は次のようになります。

[<-] 250-AUTH PLAIN LOGIN CRAM-MD5
[<-] 250 DSN

デフォルトでは、クライアントに対するサーバーの応答は、その特定のサーバーがEHLOどのSMTPプロトコル機能を受け入れるのかをクライアントに通知します。認証には、対応する単語とAUTH許可された認証メカニズムのリストを含む行が必要です。複数行の応答には、クライアントの前のコマンドの結果コードと、最後の行を除く各行の先頭にマイナス記号(ここ)が含まれます250-。答えの最後の行には、結果コードと空白文字が含まれます。

ssmtp.confサービス名に対応するポート465を使用していることを示しますsmtps

mailhub=example.com:465

したがって、関連するPostfixmaster.cfエントリは次のようになります。

smtps     inet  n       -       -       -       -       smtpd
  -o syslog_name=postfix/smtps
  -o smtpd_tls_wrappermode=yes
  -o smtpd_sasl_auth_enable=yes

これは私にとって不完全に思える。

認証された場合にのみこのポートを介してメールを送信するには、以前のサービス(ポート587で実行されているサービス)-o smtpd_client_restrictions=permit_sasl_authenticated,rejectと同様に、このポートも必要です。また、必要です。submissionsubmission-o smtpd_sasl_security_options=noanonymous

-o smtpd_sasl_type=dovecot特にPostfixでDovecot SASLを使用するには、そこに1行を追加する必要があります。以下が必要な場合があります-o smtpd_sasl_path=private/auth。 PostfixでDovecot SASLを使用する場合は、Dovecot設定で次のように指定されたDovecot SASL認証ソケットの場所を識別します。

unix_listener /var/spool/postfix/private/auth

ただし、Postfixプロセスは作業ディレクトリsmtpdとして使用されるため(実際にはルートが変更される可能性があるため)、パスの一部しか必要ありません。/var/spool/postfixsmtpdprivate/auth

STARTTLSを使用するには、代わりにポート587を使用する必要があり、診断のためにそのポートに対するPostfixのEHLO応答には250-STARTTLS

STARTTLSの一般的なイベントの順序は次のとおりです。

  1. クライアントはポート 587 に暗号化されていない接続を確立して送信します。EHLO
  2. 暗号化されていない認証データの送信はそれほどスマートではないため、サーバーの応答にはORメカニズムが含まれていますが、含まれていSTARTTLSませんAUTHPLAINLOGIN
  3. クライアントはSTARTTLSコマンドを送信し、両当事者はすぐにTLSハンドシェイクを開始します。
  4. TLS が適用されると、クライアントは別のメッセージを送信します。EHLO
  5. サーバーの応答には、AUTHサーバー管理者が許可するすべての認証メカニズムが含まれます。

私はこれがOPに非常に遅い答えであることを知っていますが、おそらく他の人がさまざまな構成部分がどのように調和しているのかを理解するのに役立ちます。 (これは間違いなく私に再びPostfix認証の知識を思い出させました。)

おすすめ記事