Outlook 不呈现 icalendar 邀请邮件

Outlook does not render icalendar invite mail

提问人:Yiğit Can Atılgan 提问时间:10/3/2023 最后编辑:Yiğit Can Atılgan 更新时间:10/3/2023 访问量:23

问:

我在 .NET Core 6 Web 应用程序中遇到 icalendar 邀请邮件结构问题。虽然大多数邮件客户端(例如Gmail)都会正确呈现我的icalendar邀请,显示是/否/可能按钮和其他详细信息;我无法使 Outlook 呈现邀请。它只是将ics文件显示为常规附件,没有事件详细信息。

我已经在 Stackoverflow 上尝试了其他解决方案,例如调整 MIME 结构。以下是我在这个过程中的函数。我做错了什么?

public async Task SendCalendarEvent(string email, string head, string content, Attachment file)
{
    string htmlBody = "some-html-body-here";
    var mail = "[email protected]";
    var pass = "mypassword";

    var client = new SmtpClient("smtp-mail.outlook.com", 587)
    {
        EnableSsl = true,
        Credentials = new NetworkCredential(mail, pass)
    };

    var message = new MailMessage(from: mail, to: email, head, htmlBody);
    message.IsBodyHtml = true;
    message.Headers.Add("Content-Type", "text/plain; name=invite.ics");
    message.Headers.Add("Content-Disposition", "attachment; filename=invite.ics");
    message.Attachments.Add(file);

    await client.SendMailAsync(message);
}

这就是我称之为的地方:

var target = "[email protected]";

StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("METHOD:REQUEST");
str.AppendLine("PRODID:Microsoft Exchange Server 2010");
str.AppendLine("VERSION:2.0");
str.AppendLine("BEGIN:VEVENT");

str.AppendLine("ORGANIZER;CN=" + "My Name" + ":mailto:" + "[email protected]");

//foreach (var attendee in entity.ExtendedProps)
{
    str.AppendLine("ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=" + "Target Name" + ":mailto:" + target);
}

str.AppendLine("DESCRIPTION;LANGUAGE=aa:");
str.AppendLine("test");

str.AppendLine("UID:" + "random-uid");

str.AppendLine("SUMMARY;LANGUAGE=aa:" + "title");
str.AppendLine("DTSTART;VALUE=DATE:" + DateTime.Now.ToString("yyyyMMdd"));
str.AppendLine("DTEND;VALUE=DATE:" + DateTime.Now.AddDays(5).ToString("yyyyMMdd"));
str.AppendLine("CLASS:PUBLIC");
str.AppendLine("PRIORITY:5");
str.AppendLine("DTSTAMP:20231001T194844Z");
str.AppendLine("TRANSP:TRANSPARENT");
str.AppendLine("STATUS:CONFIRMED");
str.AppendLine("SEQUENCE:0");

str.AppendLine("BEGIN:VALARM");
str.AppendLine("DESCRIPTION:REMINDER");
str.AppendLine("TRIGGER;RELATED=START:-PT12H");
str.AppendLine("ACTION:DISPLAY");
str.AppendLine("END:VALARM");

str.AppendLine("END:VEVENT");
str.AppendLine("END:VCALENDAR");

byte[] byteArray = Encoding.UTF8.GetBytes(str.ToString());
MemoryStream stream = new MemoryStream(byteArray);
System.Net.Mail.Attachment attach = new System.Net.Mail.Attachment(stream, "invite.ics");

//foreach (var attendee in entity.ExtendedProps)
{
    //if (!attendee.User.Mail.IsNullOrEmpty())
        await mailManager.SendCalendarEvent(target, "Test Etkinlik", "Hey", attach);
}

我希望 Outlook 呈现我的 icalendar 邀请,尝试了与此问题相关的其他主题,例如分手邮件/MIME 结构。

C# asp.net 日历 iCalendar

评论


答: 暂无答案