1

我在使用 EWS 托管 API 发送带有邀请的附件时遇到问题。约会与会者没有收到添加到约会的任何附件,但附件确实出现在创建约会的人的日历中。

这是我的代码片段:

try
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1, TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
    service.Credentials = new WebCredentials("calendar_user", "password1", "acme");
    service.Url = new Uri("https://acme.com/EWS/Exchange.asmx");

    Appointment appointment = new Appointment(service);
    service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "tin.tin@acme.com");

    String UID = "D09F3FF6-1461-414C-89E8-C05BC3B66A4A";
    appointment.ICalUid = UID;
    appointment.Subject = "Test Subject";
    appointment.Body = "Test Content.";
    appointment.Start = new DateTime(2012, 07, 11, 17, 00, 0);
    appointment.End = appointment.Start.AddMinutes(30);

    FileAttachment attachment = appointment.Attachments.AddFileAttachment(@"C:\Users\tintin\Documents\Test.xlsx");
    attachment.IsInline = false;

    appointment.RequiredAttendees.Add("tin.tin@acme.com");

    appointment.Save(SendInvitationsMode.SendToAllAndSaveCopy);
}
catch (Exception ex)
{

}
4

4 回答 4

2

看起来 EWS 在附件处理方面有可怕的限制。我找到了解决此问题的解决方法,该问题需要两次更新约会对象。

appointment.ICalUid = UID;
appointment.Subject = "Test Subject";
appointment.Body = "Test Content.";
appointment.Start = new DateTime(2012, 07, 11, 17, 00, 0);
appointment.End = appointment.Start.AddMinutes(30);

FileAttachment attachment = appointment.Attachments.AddFileAttachment(@"C:\Users\tintin\Documents\Test.xlsx");
attachment.IsInline = false;

appointment.Save(folderCalendar, SendInvitationsMode.SendToNone);
appointment.RequiredAttendees.Add("tin.tin@acme.com");

appointment.Update(ConflictResolutionMode.AutoResolve, SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
于 2012-07-13T19:00:36.940 回答
0

看起来这个问题是 Exchange Server 2010 Service Pack 1 特有的。我遇到了类似的问题,当我将版本更改为 SP2 时,问题得到了解决。下面的代码解决了问题

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
于 2013-07-10T15:31:32.353 回答
0

第二次更新起到了作用,但它会导致底部的会议被取消。不能在产品中使用。将版本更改为 SP2 不起作用。

Still find a better solution.

于 2014-10-28T09:34:15.960 回答
0

Yes, EWS has some issue, while updating the meeting with new attachments it is not getting updated for the first time. Needed 2 instances to update it.

Microsoft.Exchange.WebServices.Data.Appointment meet1 = await 
Microsoft.Exchange.WebServices.Data.Appointment.Bind(service, strMessageID);
                                meet1.Attachments.Clear();
                                foreach (FileUpload Item in 
objCreateEvent.strAttachmentUploadPath)
                                {
                                    meet1.Attachments.AddFileAttachment(Item.fileName, 
Item.filePath);
                                }
                                meet1.RequiredAttendees.Clear();
                                foreach (string ToItem in objToIds)
                                {
                                    meet1.RequiredAttendees.Add(ToItem);
                                }
                                await 
meet1.Update(ConflictResolutionMode.AlwaysOverwrite, 
SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
                                Microsoft.Exchange.WebServices.Data.Appointment 
meeting2 = await Microsoft.Exchange.WebServices.Data.Appointment.Bind(service, 
strMessageID);
                                meeting2.Attachments.Clear();
                                foreach (FileUpload Item in 
objCreateEvent.strAttachmentUploadPath)
                                {
                                    
meeting2.Attachments.AddFileAttachment(Item.fileName, Item.filePath);
                                }
                                meeting2.RequiredAttendees.Clear();
                                foreach (string ToItem in objToIds)
                                {
                                    meeting2.RequiredAttendees.Add(ToItem);
                                }
                                await 
meeting2.Update(ConflictResolutionMode.AlwaysOverwrite, 
SendInvitationsOrCancellationsMode.SendToAllAndSaveCopy);
于 2021-03-04T13:24:28.350 回答