.net5 中最初的 C# 流程多年来一直在发送具有 Ecalendar 结构的电子邮件,但对于在 Exchange Online 下迁移的用户来说,邀请不再被理解。
例如,如果发送到 Gmail 地址,邀请仍然有效。 新服务器可以正确处理从谷歌日历发送的约会。
所以我猜这意味着 Exchange Online 无法理解 C# 进程中的某些内容。 该过程使用 MailMessage 类,但我尝试了其他类但没有成功
这里是使用 .net7 进行最小化简化的示例。在在线交换中,我们可以访问附件 (invitation.ics),但该消息不会直接作为 Icalendar 邀请处理。在 Gmail 中,该消息被很好地理解为约会。
using System;
using System.Net.Mail;
using System.Text;
try
{
SmtpClient clientSmtp = new SmtpClient("mysmtpserver");
using (MailMessage mail = new MailMessage("[email protected]", "[email protected]"))
{
mail.Subject = "test";
mail.Body = "test";
mail.To.Add("[email protected]");
// Ajouter le fichier iCalendar
byte[] fichierICalendar = CreerFichierICalendar();
mail.Attachments.Add(new System.Net.Mail.Attachment(new System.IO.MemoryStream(fichierICalendar), "invitation.ics", "text/calendar"));
clientSmtp.Send(mail);
Console.WriteLine("Invitation envoyée avec succès.");
}
}
catch (Exception ex)
{
Console.WriteLine("Une erreur s'est produite lors de l'envoi de la demande de réunion : " + ex.Message);
}
static byte[] CreerFichierICalendar()
{
// Création d'un événement iCalendar
StringBuilder builder = new StringBuilder();
builder.AppendLine("BEGIN:VCALENDAR");
builder.AppendLine("VERSION:2.0");
builder.AppendLine("PRODID:-//MyApp//EN");
builder.AppendLine("BEGIN:VEVENT");
builder.AppendLine("UID:" + Guid.NewGuid());
builder.AppendLine("DTSTAMP:" + DateTime.UtcNow.ToString("yyyyMMddTHHmmssZ"));
builder.AppendLine("DTSTART:20230710T180000");
builder.AppendLine("DTEND:20230710T190000");
builder.AppendLine("SUMMARY:Événement spécial");
builder.AppendLine("DESCRIPTION:Événement spécial le 10 juin à 18h");
builder.AppendLine("END:VEVENT");
builder.AppendLine("END:VCALENDAR");
return Encoding.UTF8.GetBytes(builder.ToString());
}
我必须使用另一个课程吗?或者是否缺少强制参数? 谢谢
这是一个 contentType 问题,应在 calendarView 级别包含参数“method”:“REQUEST”