前提・実現したいこと
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
あなたの回答
tips
プレビュー