使用DDay.iCal的iCalendar请求响应

时间:2016-03-14 15:36:00

标签: c# icalendar dday

我正在尝试回复通过Outlook 2013发送的会议邀请。为此,我正在使用DDay.iCal库和以下代码:

public static string GenerateAppointmentResponse(Appointment importedAppointment, MeetingRequestAcceptanceType acceptanceType)
{
    var iCal = new iCalendar
    {
        Method = "PUBLISH",
        Version = "2.0",
        ProductID = MyhProductIdentifier
    };

    var evt = iCal.Create<Event>();

    switch (importedAppointment.PrivacyStatus)
    {
        case AppointmentPrivacyStatus.None:
            evt.Class = "PRIVATE";
            evt.Transparency = TransparencyType.Opaque;
            break;
        case AppointmentPrivacyStatus.AvailabilityOnly:
            evt.Class = "PUBLIC";
            evt.Transparency = TransparencyType.Transparent;
            break;
        case AppointmentPrivacyStatus.LimitedDetails:
            evt.Class = "PUBLIC";
            evt.Transparency = TransparencyType.Transparent;
            break;
        case AppointmentPrivacyStatus.FullDetails:
            evt.Class = "PUBLIC";
            evt.Transparency = TransparencyType.Transparent;
            break;
        default:
            throw new ArgumentOutOfRangeException();
    }

    evt.Summary = importedAppointment.Subject;
    evt.Start = new iCalDateTime(importedAppointment.Start);
    evt.Duration = importedAppointment.End - importedAppointment.Start;
    evt.Description = importedAppointment.Description;
    evt.Location = importedAppointment.Location;
    evt.IsAllDay = importedAppointment.IsAllDay == true;
    evt.UID = importedAppointment.ICalendarUid;

    string organizer = importedAppointment.CreatedBy ?? Environment.UserName;
    if (string.IsNullOrWhiteSpace(organizer))
    {
        throw new Exception("The Organizer is mandatory.");
    }

    evt.Organizer = new Organizer(organizer);

    if (!string.IsNullOrWhiteSpace(importedAppointment.RecurrenceInfo))
    {
        var rp = new RecurrencePattern(importedAppointment.RecurrenceInfo);
        evt.RecurrenceRules.Add(rp);
    }

    //// REQUEST will update an existing event with the same
    //// UID (Unique ID) and a newer time stamp.
    //if (updatePreviousEvent)
    //{
    //    iCal.Method = "REQUEST";
    //}

    string result = new iCalendarSerializer().SerializeToString(iCal);
    return result;
}

现在,当在备用视图中通过SMTP发送生成的ics字符串时,会议似乎是从原始收件人发送的,而不是来自会议邀请收件人的回复。

// Construct the calendar view
string appointmentData = CalendarHelper.GenerateAppointment(meetingRequestResponse.ImportedAppointment, meetingRequestResponse.AcceptanceType);

var appointment = new AlternateView();
appointment.SetContent(appointmentData, "text/calendar");
appointment.ContentType.Parameters.Add("method", "REQUEST");

// Construct the message
var mailMessage = new MailMessage();
mailMessage.AlternateViews.Add(appointment);

我错过了什么?

1 个答案:

答案 0 :(得分:0)

method需要在内容类型标头和REPLY iCalendar属性中设置为REQUEST而不是PUBLISHMETHOD。这可能不是唯一的问题,但它是最明显的问题。

如果仍然无法解决问题,请分享您生成+标题的实际电子邮件。