0
ディレクトリ内のlastwritetimeを参照する電子メール警告を送信しようとしています.15分を超えるものは電子メール警告を送信します。ここに私のコードと私がやろうとしていることがあります。ディレクトリ内の15分を超える警告メールファイル
MailMessage CyclopsCentral = new MailMessage();
SmtpClient client = new SmtpClient(server);
CyclopsCentral.From = new System.Net.Mail.MailAddress("[email protected]");
CyclopsCentral.To.Add("[email protected]");
CyclopsCentral.Subject = "Cyclops Central Not Updating";
CyclopsCentral.Body = "Cyclops Central is not updating, please check the management center.";
CyclopsCentral.Priority = MailPriority.High;
try
{
string[] files = Directory.GetFiles(@"\\Users\!NCDSPOTVIEW\Desktop\ScreenScrapes\Chicago\ScreenScrape\ScreenScrape.png\");
foreach (string file in files)
{
FileInfo fi = new FileInfo("ScreenScrape.png");
if (fi.LastWriteTime < DateTime.Now.AddHours(-1))
fi.Send(CyclopsCentral);
}
//client.LogFileName = "d:\\smtp.txt";
Console.WriteLine("Start to send email ...");
//client.Send(CyclopsCentral);
Console.WriteLine("email was sent successfully");
}
catch (Exception ep)
{
Console.WriteLine("failed to send email with the following error:");
Console.WriteLine(ep.Message);
}
}
}
}
コードの問題点は何ですか?それは例外をスローしますか?頻繁にメールを送信しますか?それはうまくいったが、メールは受信されないと言うか? (ちなみに、 "client.Send"の行はコメントアウトされています) –
あなたはDirectory.GetFiles()の出力を使用していません(結果を丸めていますが、コード内のファイルを使用していません)。 –
また、プライバシー上の理由から、あなたのコードからメールアドレスを削除したいかもしれません。 –