问题
I've been stuck on this problem for hours at this point and I can't figure out the problem.
I would like to email(gmail) an invitation through an iCal file,
It works(reciever can get a invitation and can click yes to add this invitation to reciever's calendar) if I send one event,
but its failed(the gmail will just only show an invitation , and if i click yes that i want to add it to my calendar, its only add one invitation to my calendar) if I send two events.
The code is the following:
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;
}
回答1:
the problem is not with your code (though a different uid is mandatory as per rfc5545), but with the GUI from the different calendar application.
if we stretch your use case, their could be potentially 100's or 1000's of events in an email and how should the GUI look like? 100's or 1000's of buttons in series to be clicked for each individual event?
so eventhough your code is correct and the iMIP (RFC6047) also says more than 1 VEVENT can be included, it is not good practice to have more than 1 event as the user needs to approve them one by one.
if what you want is to have 2 instances
of the same event (hence the same UID), you should use the RDATE property to specify your 2 dates in one EVENT and then your user can accept the invite for 1 event (which will have 2 instances).
来源:https://stackoverflow.com/questions/14545458/email-invitation-via-an-ical-file