SMTP を使用して、ユーザーの Outlook 受信トレイに送信される自動電子メールを実装しました。別のビューを使用して、カレンダーの予定が同時に送信されます。また、ブラウザで html ファイルを開くためにダブルクリックできる html アイコンもあります。現在、同じコードを使用していますが、交換サーバーを使用しているため、結果が異なります。同じコードを使用しているにもかかわらず、動作が異なります。Exchange の使用中にブロックされる機能はありますか? この問題を回避して同じ結果を得るにはどうすればよいですか?
SMTP のみを使用したスクリーンショット:
SMTP のみを使用したコード:
//Message
MailMessage msg = new MailMessage();
mailMessage.From = new MailAddress("from@test.com");
mailMessage.To.Add(new MailAddress("to@test.com"));
mailMessage.Subject = "Subject";
//Calendar
System.Net.Mime.ContentType ctCal = new System.Net.Mime.ContentType("text/calendar");
ctCal.Parameters.Add("method", "REQUEST");
AlternateView calendarView =
AlternateView.CreateAlternateViewFromString(GetCalendarEvent(mailMessage, "Test",
"REQUEST", strReviewByDate, strReviewByDate, "").ToString(), ctCal);
mailMessage.AlternateViews.Add(calendarView);
//Read Html file.
String filePath = "C:\\Path\\To\\File.html";
StreamReader sr = File.OpenText(strFilePath);
String body = sr.ReadToEnd();
sr.Close();
//I make other changes to the html file here//
//Save Html file
FileStream fs = File.OpenWrite("C:\\Path\\To\\EditedFile.html");
StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
writer.Write(strBody);
writer.Close();
//Add Attachment to message
mailMessage.Attachments.Add(new Attachment("C:\\Path\\To\\EditedFile.html"));
//Send the email
SmtpClient smtpClient = new SmtpClient("127.0.0.1", 25);
smtpClient.Send(mailMessage);
Exchange で使用するように変更した後のスクリーンショット:
Exchange で使用するコードの変更:
exchange で使用するために上記のコードから変更された唯一のコードは、次の行にあります。
SmtpClient smtpClient = new SmtpClient("exchange.test.example.com", 25);