1

当用户在我们的网站上注册时,我想向他们发送一封电子邮件,允许他们使用他们注册的课程自动更新他们的日历。在大多数情况下,这将是多天/多事件。

作为测试,我使用 DDay.ical 创建多事件请求。但是,Outlook 或 iPhone 邮件应用程序似乎都没有注意到 ical 附件中的第二个事件。

我知道 iCal 标准支持多个事件。这并不意味着所有客户都支持这种情况。其他客户端是否支持多事件请求?

我不认为我在代码中做错了什么,但我会发布我的代码片段以确保:

                    // Create event part.
                iCalendar iCal1 = new iCalendar();
                iCal1.AddLocalTimeZone();

                iCal1.Method = "REQUEST";

                Event evt1 = iCal1.Create<Event>();
                evt1.Start = new iCalDateTime(new DateTime(2014, 8, 4, 12, 30, 00, DateTimeKind.Local));
                evt1.End = evt1.Start.AddMinutes(30);
                evt1.IsAllDay = false;
                evt1.Summary = string.Format("Lesson - {0}", evt1.Start.ToString("MM/dd"));
                evt1.Location = "Anytown";

                // Add recipients for appointment.
                Attendee att1 = new Attendee("mailto:" + "me@MyDomain.com");
                att1.RSVP = false;
                att1.CommonName = "Me Jones";
                evt1.Attendees.Add(att1);


                Event evt2 = iCal1.Create<Event>();
                evt2.Start = new iCalDateTime(new DateTime(2014, 8, 11, 12, 30, 00, DateTimeKind.Local));
                evt2.End = evt1.Start.AddMinutes(30);
                evt2.IsAllDay = false;
                evt2.Summary = string.Format("Lesson - {0}", evt2.Start.ToString("MM/dd"));
                evt2.Location = "AnyTown";

                // Add recipients for appointment.
                Attendee att2 = new Attendee("mailto:" + "me@MyDomain.com");
                att2.RSVP = false;
                att2.CommonName = "Me Jones";
                evt2.Attendees.Add(att2);



                iCalendarSerializer serializer1 = new iCalendarSerializer();

                string t = serializer1.SerializeToString(iCal1);
                Byte[] bytes = System.Text.Encoding.ASCII.GetBytes(t);

                using (var ms = new System.IO.MemoryStream(bytes))
                {
                    using (var a = new System.Net.Mail.Attachment(ms, "meeting.ics", "text/calendar")) //Either load from disk or use a MemoryStream bound to the bytes of a String
                    {
                        a.ContentDisposition.Inline = true;             //Mark as inline
                        msg.Attachments.Add(a);                          //Add it to the message
                        Mailer.Send(msg);

                    }

                }
4

1 回答 1

3

不幸的是,您完全依赖于各种电子邮件客户端中 Icalendar 的实现,这些通常非常保护用户的日历。它们通常都支持多事件日历,但是“直接进入”用户日历的邀请必须一次发送一个事件。我不知道有任何例外。

要处理包含多个事件的 Icalendar 附件,例如在 Outlook 中,您需要将附件保存到磁盘,导航到它并打开它。然后它会作为单独的日历打开,您需要将事件一一拖到日历中。恶梦。这很少值得费心去开发。

当然,另一种选择是在您的网站上托管 Icalendar,并通过在其客户端中输入日历 URL 来让您的用户订阅。这样做的好处是更改会自动传播,但电子邮件客户端仍会将事件视为外部事件(没有自动提醒,在 Outlook 中默认是在单独的窗格中显示它们,Gmail 至少在同一网格上显示来自不同日历的事件。 )

于 2014-07-29T15:21:26.300 回答