アプリケーションからメールを送信するために、以下のような感じでMailKit.Net.Smtpを使用している。
SmtpClient cli = new SmtpClient();
await cli.ConnectAsync("smtp.boo.foo",25);
await cli.SendAsync(msg);Connectメソッドで、サーバーとポートのみ指定する形。今までは普通に動いていたのだが、SMTPサーバーをIISのSMTPからLinux sendmailに変更したところ、以下のような例外が発生した。
An error occurred while attempting to establish an SSL or TLS connection.
The host name (xxx.xxx.xxx) did not match the name given in the server's SSL certificate (yyy.yyy.yyy).どうも、START TLSの関係らしい。色々調べてみたが、取敢えず、以下の方法で解決はした。
await cli.ConnectAsync("smtp.boo.foo",25,SecureSocketOptions.None);しかし、最初の様なコードを持つアプリが結構あるため、SMTPサーバー側でどうにかならないか調べてみたところ、sendmailの場合だと、accessに下記の設定を行なえば、「SMTPサーバーはSTART TLSをサポートしない」という宣言?になるらしい。
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package.
#
# If you want to use AuthInfo with "M:PLAIN LOGIN", make sure to have the
# cyrus-sasl-plain package installed.
#
# By default we allow relaying from localhost...
Srv_Features: S
・・・この設定を行ない、sendmailを再起動した後に、元のコードでメール送信を行なったところ、正常にメールが送信された。
社内でしか使用しないSMTPリレーサーバーなので、TLSは必要ないため、これで良しとしよう。
でも、この方法見つけたのは、結構な数のアプリコード直した後だったりする。Orz





Users Today : 29
Users Yesterday : 11
Users Last 7 days : 214
Users Last 30 days : 824
Users This Month : 228
Users This Year : 2690
Total Users : 97205
Views Today : 30
Views Yesterday : 12
Views Last 7 days : 269
Views Last 30 days : 1034
Views This Month : 290
Views This Year : 3212
Total views : 135658
Who's Online : 0