在这一点上,我已经被这个问题困扰了几个小时,我无法弄清楚这个问题。
我想通过 iCal 文件通过电子邮件(gmail)发送邀请,
如果我发送一个事件,它可以工作(接收者可以获得邀请,并且可以单击“是”将此邀请添加到接收者的日历中),
但它失败了(Gmail 只会显示一个邀请,如果我点击是,我想将它添加到我的日历,它只会向我的日历添加一个邀请)如果我发送两个事件。
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
MailMessage msg = new MailMessage("testxxx@gmail.com", "testxxx@gmail.com", "test", "test");
msg.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new NetworkCredential("test", "test");
msg = GetCalanderInviteMsg3(msg);
smtp.EnableSsl = true;
smtp.Send(msg);
}
public static MailMessage GetCalanderInviteMsg3(MailMessage msg)
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("BEGIN:VCALENDAR");
sb.AppendLine("PRODID:-//Google Inc//Google Calendar 70.9054//EN");
sb.AppendLine("VERSION:2.0");
sb.AppendLine("CALSCALE:GREGORIAN");
sb.AppendLine("METHOD:PUBLISH");
sb.AppendLine("X-WR-CALNAME:test");
sb.AppendLine("X-WR-TIMEZONE:Asia/Taipei");
sb.AppendLine("X-WR-CALDESC:");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("DTSTART;VALUE=DATE:20130705")`
sb.AppendLine("DTEND;VALUE=DATE:20130706");
sb.AppendLine("DTSTAMP:20130127T040705Z");
sb.AppendLine("UID:" + "c643b569-9ba8-45c1-9264-8f160411872a");
sb.AppendLine("CREATED:20130624T082605Z");
sb.AppendLine("DESCRIPTION:");
sb.AppendLine("LAST-MODIFIED:" + "2013127T054310Z");
sb.AppendLine("LOCATION:");
sb.AppendLine("SEQUENCE:0");
sb.AppendLine("STATUS:CONFIRMED");
sb.AppendLine("SUMMARY:event1");
sb.AppendLine("TRANSP:TRANSPARENT");
sb.AppendLine("END:VEVENT");
sb.AppendLine("BEGIN:VEVENT");
sb.AppendLine("DTSTART;VALUE=DATE:20130703");
sb.AppendLine("DTEND;VALUE=DATE:20130704");
sb.AppendLine("DTSTAMP:20130127T040730Z");
sb.AppendLine("UID:" + "84395bf9-875e-4925-864f-910309e0a355");
sb.AppendLine("CREATED:20080624T082556Z");
sb.AppendLine("DESCRIPTION:");
sb.AppendLine("LAST-MODIFIED:" + "2013127T054320Z");
sb.AppendLine("LOCATION:");
sb.AppendLine("SEQUENCE:0");
sb.AppendLine("STATUS:CONFIRMED");
sb.AppendLine("SUMMARY:event2");
sb.AppendLine("TRANSP:TRANSPARENT");
sb.AppendLine("END:VEVENT");
sb.AppendLine("END:VCALENDAR");
System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType("text/calendar");
ct.Parameters.Add("method", "REQUEST");
AlternateView avCal = AlternateView.CreateAlternateViewFromString(sb.ToString(), ct);
msg.AlternateViews.Add(avCal);
return msg;
}