6

私はコンソール アプリケーションを持っており、メッセージング目的でメールキット パッケージをインストールしました。

mailkit smtp クライアントをテストするためのメイン メソッドのコードがあります。私はsmtp4devダミーサーバーを実行しており、クライアントコードは認証部分がコメントされたgithubのメールキットのサンプルコードであり、ホストはlocalhostでポート26で、smtp4dev構成と一致しています。

クライアント コードが smtp4devstop runningで実行され、未処理の例外が発生すると、IOException: Unable to read data from the transport connection: an existing connection was forcibly closed by the remote host.

メールキット クライアントからメッセージを受信するように smtp4dev を設定するにはどうすればよいですか?

4

2 に答える 2

12

試行錯誤の末、以下の配置で成功することができました。 smtp4dev オプション

私のコードはhttps://github.com/jstedfast/MailKit#sending-messagesに似ています:

public void DoMail()
{
    var message = new MimeMessage();
    message.From.Add(new MailboxAddress("Joey", "joey@friends.com"));
    message.To.Add(new MailboxAddress("Alice", "alice@wonderland.com"));
    message.Subject = "How you doin?";

    message.Body = new TextPart("plain")
    {
        Text = @"Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.

Will you be my +1?

-- Joey
"
    };

    using (var client = new SmtpClient())
    {
        // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
        client.ServerCertificateValidationCallback = (s, c, h, e) => true;

        client.Connect("localhost", 25, false);

        // Note: since we don't have an OAuth2 token, disable
        // the XOAUTH2 authentication mechanism.
        client.AuthenticationMechanisms.Remove("XOAUTH2");

        // Note: only needed if the SMTP server requires authentication
        //client.Authenticate("joey", "password");

        client.Send(message);
        client.Disconnect(true);
    }
}

imgur にアクセスできない場合:
ドメイン名: localhost
リッスン インターフェイス: 0.0.0.0
ポート番号: 25 (ただし、Dalsier の場合、Dalsier は 26 を使用します)
拡張機能:

  • [ ] 暗黙の SSL/TLS
  • [x] 8BITMIME
  • [ ] STARTTLS
  • [ ] 認証
  • [×] サイズ

SSL/TLS 証明書:なし
SSL/TLS 証明書のパスワード:なし
最大メッセージ サイズ (バイト): 0
受信タイムアウト (ミリ秒): 30000
オプション:

  • [ ] 認証が必要
  • [ ] 安全な接続が必要
  • [ ] 安全な接続を介したクリア テキスト認証のみを許可する
于 2016-10-19T20:00:01.993 に答える