C# iCal 邀请未正确显示在 Outlook 中
我的一个客户无法看到与我相同格式的电子邮件。我使用的是 Outlook 2007,而他们使用的是 2003、2007 和 2010 的混合版本。邀请对我来说显示得很好,但他们看到的只是一封普通的电子邮件,并且显示所有 HTML 标记,而不是格式化的电子邮件。
这是我现在所拥有的:
protected void SendMessage(MailMessage message, bool cancel)
{
AlternateView av = GetInviteContent(cancel);
message.AlternateViews.Add(av);
base.SendMessage(message);
}
private AlternateView GetInviteContent(bool cancel)
{
StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("VERSION:2.0");
if(cancel)
str.AppendLine("METHOD:CANCEL");
else
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VEVENT");
if(cancel)
str.AppendLine("STATUS:CANCELLED");
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", StartTime));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", EndTime));
str.AppendLine(string.Format("LOCATION:{0}", Location));
str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
str.AppendLine(string.Format("DESCRIPTION:{0}", Body));
str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", Body));
str.AppendLine(string.Format("SUMMARY:{0}", Subject));
str.AppendLine(string.Format("ORGANIZER;CN={0}:MAILTO:{1}", From.Email, From.FormalName));
foreach (var to in To)
{
str.AppendLine(string.Format("ATTENDEE;CN={0};ROLE=REQ-PARTICIPANT:MAILTO:{1}", to.FormalName, to.Email));
}
str.AppendLine("BEGIN:VALARM");
str.AppendLine(string.Format("TRIGGER:-PT{0}M", Reminder.Minutes));
str.AppendLine("ACTION:DISPLAY");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");
str.AppendLine("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
if(cancel)
ct.Parameters.Add("method", "CANCEL");
else
ct.Parameters.Add("method", "REQUEST");
return AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
}
I have a client that cannot see the same format of the emails I have. I am on Outlook 2007 and they are on a mix of 2003, 2007, and 2010. The invite shows up fine for me, but all they see is a normal email and all of the HTML markup shows, instead of the email being formatted.
Here is what I have right now:
protected void SendMessage(MailMessage message, bool cancel)
{
AlternateView av = GetInviteContent(cancel);
message.AlternateViews.Add(av);
base.SendMessage(message);
}
private AlternateView GetInviteContent(bool cancel)
{
StringBuilder str = new StringBuilder();
str.AppendLine("BEGIN:VCALENDAR");
str.AppendLine("VERSION:2.0");
if(cancel)
str.AppendLine("METHOD:CANCEL");
else
str.AppendLine("METHOD:REQUEST");
str.AppendLine("BEGIN:VEVENT");
if(cancel)
str.AppendLine("STATUS:CANCELLED");
str.AppendLine(string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}", StartTime));
str.AppendLine(string.Format("DTEND:{0:yyyyMMddTHHmmssZ}", EndTime));
str.AppendLine(string.Format("LOCATION:{0}", Location));
str.AppendLine(string.Format("UID:{0}", Guid.NewGuid()));
str.AppendLine(string.Format("DESCRIPTION:{0}", Body));
str.AppendLine(string.Format("X-ALT-DESC;FMTTYPE=text/html:{0}", Body));
str.AppendLine(string.Format("SUMMARY:{0}", Subject));
str.AppendLine(string.Format("ORGANIZER;CN={0}:MAILTO:{1}", From.Email, From.FormalName));
foreach (var to in To)
{
str.AppendLine(string.Format("ATTENDEE;CN={0};ROLE=REQ-PARTICIPANT:MAILTO:{1}", to.FormalName, to.Email));
}
str.AppendLine("BEGIN:VALARM");
str.AppendLine(string.Format("TRIGGER:-PT{0}M", Reminder.Minutes));
str.AppendLine("ACTION:DISPLAY");
str.AppendLine("DESCRIPTION:Reminder");
str.AppendLine("END:VALARM");
str.AppendLine("END:VEVENT");
str.AppendLine("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
if(cancel)
ct.Parameters.Add("method", "CANCEL");
else
ct.Parameters.Add("method", "REQUEST");
return AlternateView.CreateAlternateViewFromString(str.ToString(), ct);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我花了很长时间试图弄清楚这个问题,最后发现这个对我有用(在 Outlook 2007 和 2010 中进行了测试)。
注意:我还没有尝试过取消,这只适用于请求。
I spent ages trying to figure it out and landed on this which works for me (tested in Outlook 2007 and 2010).
Note: I've not tried cancel yet, this only works for Request.