テーブルの行を更新する方法があります。これは、変更の影響を受けるすべての企業の顧客を通過し、それぞれの顧客に、この変更を通知する必要があるすべてのすべてのユーザーに、pdfファイルを添付して電子メールで送信します。ファイルは、サーバー上の特定の場所に保存されます。 これは、このメソッド呼び出しから送信される電子メールが20〜500件になる可能性があります。添付ファイル付きの大量メールを送信するときに、既存の接続がリモートホストによって強制的に閉じられました
このメソッドはクライアントによって一度呼び出され、次にサーバーはすべてのジョブを実行します。電子メールに使用されているPDFファイルは決して変更されず、常に変わりません。
この方法については、より良い構造があるかもしれません。あるいは、スクリプトを実行するときにサーバーのリソースが不足するのを避けるために、何らかの保護を置くことができますか?
今のところ、次のエラーが発生します。An existing connection was forcibly closed by the remote host
System.Net.SocketsException: An existing connection was forcibly closed by the remote host
カスタマーサービスが私に送信したスタックトレースは次のとおりです。ここで
方法のコードの大部分である:あなたのメールサーバのログを確認する必要があり
string attach = null;
string mergerFile = FileHelper.DirectoryName.MergerDocumentDirectory(instId) + mergerDocumentFileName;
if (System.IO.File.Exists(mergerFile))
attach = mergerFile;
string subject = "subject";
StringBuilder sbEmailBody = new StringBuilder();
sbEmailBody.Append("the email body etc...");
foreach(Company in companies){
//do some business logic here
foreach(User in Company.Users){
CustomLibrary.Mail.SendEmail("[email protected]", user.Email.Trim(), "", "", subject, true, emailBody, attach);
}
}
方法
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
smtpClient.Host = WebConfigurationManager.AppSettings["mailServer"];
smtpClient.Port = 25;
message.From = new MailAddress(EmailFrom);
message.To.Add(EmailTo);
message.Subject = EmailSubject;
#region mail body
System.Text.StringBuilder sb = new System.Text.StringBuilder();
//add some header, body and footer to the email body here
#endregion
// Message body content
message.Body = sb.ToString();
//Attachment
message.Attachments.Clear();
if (!String.IsNullOrEmpty(AttachmentFile))
{
Attachment myattach = new Attachment(AttachmentFile);
message.Attachments.Add(myattach);
}
// Send SMTP mail
smtpClient.Send(message);
[ランダム "既存の接続がリモートホストによって強制的に閉じられました。 TCPリセット後](https://stackoverflow.com/questions/32502207/random-an-existing-connection-was-forcibly-closed-by-remote-host-after-a) –
@ rogue1nib私は役職。それは別の状況だと私には思われる – Greg
私は自分の問題をどのように解決するかに関する説明がありますか?私は助けてくれる投稿から何も読んでいない – Greg