質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

メール

メールは、コンピュータネットワークを利用し、 情報等を交換する手段のことです。

Q&A

0回答

3686閲覧

SmtpClientによるメール送信時にSystem.ComponentModel.Win32Exceptionエラーが発生する

infts

総合スコア22

C#

C#はマルチパラダイムプログラミング言語の1つで、命令形・宣言型・関数型・ジェネリック型・コンポーネント指向・オブジェクティブ指向のプログラミング開発すべてに対応しています。

.NET Framework

.NET Framework は、Microsoft Windowsのオペレーティングシステムのために開発されたソフトウェア開発環境/実行環境です。多くのプログラミング言語をサポートしています。

メール

メールは、コンピュータネットワークを利用し、 情報等を交換する手段のことです。

0グッド

1クリップ

投稿2018/07/02 04:26

編集2018/07/06 08:01

前提・実現したいこと

Visual Studio 2013(.Net Framework4.5)にて
メール一斉送信システムを作成しておりますが
メール送信処理時に以下の2つのエラーが発生します。

・パターン1
System.ComponentModel.Win32Exception (0x80004005):
関数に提供されているバッファーが小さすぎます。

・パターン2
System.ComponentModel.Win32Exception (0x80004005):
検証のために提供されたメッセージまたは署名が変更されています

上記エラーは、必ず発生するものではないため、再現条件は不明ですが
発生する頻度としてはパターン1のエラーがの方が高いです。
対応策としては、どのようなことが考えられますでしょうか?

発生している問題・エラーメッセージ

以下、ログに残したスタックトレースです。

・パターン1

System.Collections.Generic.List`1[System.String]:System.Security.Authentication.AuthenticationException: SSPI への呼び出しに失敗しました。内部例外を参照してください。 ---> System.ComponentModel.Win32Exception: 関数に提供されているバッファーが小さすぎます。
--- 内部例外スタック トレースの終わり ---
場所 System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
場所 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
場所 System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
場所 System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
場所 System.Net.Mail.SmtpConnection.Flush()
場所 System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)
場所 System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
場所 System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
場所 System.Net.Mail.SmtpClient.GetConnection()
場所 System.Net.Mail.SmtpClient.Send(MailMessage message)

・パターン2

System.Collections.Generic.List`1[System.String]:System.Security.Authentication.AuthenticationException: SSPI への呼び出しに失敗しました。内部例外を参照してください。 ---> System.ComponentModel.Win32Exception: 検証のために提供されたメッセージまたは署名が変更されています
--- 内部例外スタック トレースの終わり ---
場所 System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
場所 System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
場所 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
場所 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
場所 System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result)
場所 System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size)
場所 System.Net.Mail.SmtpConnection.Flush()
場所 System.Net.Mail.ReadLinesCommand.Send(SmtpConnection conn)
場所 System.Net.Mail.EHelloCommand.Send(SmtpConnection conn, String domain)
場所 System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
場所 System.Net.Mail.SmtpClient.GetConnection()
場所 System.Net.Mail.SmtpClient.Send(MailMessage message)

該当のソースコード

C#
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
//JISコード
System.Text.Encoding enc = System.Text.Encoding.GetEncoding("iso-2022-jp");
msg.SubjectEncoding = enc;
msg.BodyEncoding = enc;
msg.BodyTransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
msg.Headers.Add("Message-Id", "<" + Guid.NewGuid() + "@xxx.co.jp(送信ドメイン)>");
//その他にmsgに送信先や件名、本文などの情報をセット

using (System.Net.Mail.SmtpClient sc = new System.Net.Mail.SmtpClient())
{
//SMTPサーバーなどを設定する
sc.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
sc.EnableSsl = true;
sc.Host = XXX;
sc.Port = 587;
sc.Credentials = new System.Net.NetworkCredential(XXX, YYY);
//メッセージを送信する
sc.Send(msg);
}

試したこと

・複数のメールを送信する間隔が短すぎるのが原因だと仮定して
メール送信する間隔を10秒にして該当のソースコードにある
メール送信処理をしてみましたが、
エラーが発生しました。

補足情報(FW/ツールのバージョンなど)

・普段のメーラーはThuderbirdを使用しており、
メール一斉送信システムを動作させるPCで
メーラーは常時起動している状態です。

エラーメッセージで検索し、
以下のページの内容は確認しましたが、原因は分かりませんでした。

・VB.netプログラムでSFTPサーバよりファイル送受信をすると予期せぬエラーが発生する
https://teratail.com/questions/48680

・特定のクライアントで SecurityNegotiationException が出る
https://social.msdn.microsoft.com/Forums/windowsmobile/ja-JP/2ba3b361-4d41-4418-bec9-8c3c1fda2722/29305234501239812463125211245212450125311248812391?forum=wcfja

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問