1

我正在使用 EWS API 将约会导出到用户的交换日历。它工作正常,但我在约会中注意到 html 的格式不正确,表格对齐等。因此,我尝试将约会正文类型属性设置为 HTML,但在我设置属性的那一行上得到了 ServiceObjectPropertyException 说“您必须先加载或分配此属性,然后才能读取它的值”。

                User SelectedUser = UserController.GetExchangeCredentials(UserID);

                //If they have their exchange credentials setup then create the appointment in their exchange calender
                if (SelectedUser.ExchangeUsername != String.Empty)
                {
                    Client ClientInfo = ClientController.GetContactInfoForCalenderAppointment(int.Parse(btn_SubmitNextContactDate.CommandArgument.ToString()), int.Parse(ddl_Contact.SelectedValue));

                    //Setup the exchange service with the user credentials of that receiving the appointment
                    ExchangeService Service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
                    Service.UseDefaultCredentials = false;
                    Service.Credentials = new WebCredentials(SelectedUser.ExchangeUsername, SelectedUser.ExchangePassword, SelectedUser.ServerDomain);
                    Service.AutodiscoverUrl(SelectedUser.Email);

                    //Create the appointment
                    Microsoft.Exchange.WebServices.Data.Appointment Appointment = new Microsoft.Exchange.WebServices.Data.Appointment(Service);
                    Appointment.Body.BodyType = BodyType.HTML;
                    Appointment.Subject = "Next Contact Date for " + OperatingName.Text;                        
                    Appointment.Body = "<table><tr><td><b>Client Name:</b></td><td>" + ClientName.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Operating Name:</b></td><td>" + OperatingName.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Service:</b></td><td>" + ddl_ServiceType.SelectedItem.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Method:</b></td><td>" + ddl_ContactMethod.SelectedItem.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Name:</b></td><td>" + ddl_Contact.SelectedItem.Text + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Phone:</b></td><td>" + ClientInfo.Contacts[0].Phone + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Contact Email:</b></td><td>" + ClientInfo.Contacts[0].Email + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Client Address 1:</b></td><td>" + ClientInfo.Address1 + "</td></tr>";
                    Appointment.Body += "<tr><td><b>Note:</b></td><td>" + txt_NextContactDateNote.Content + "</td></tr></table>";
                    Appointment.Start = DateTime.Parse(txt_NextContactDate.Text);
                    Appointment.End = DateTime.Parse(txt_NextContactDate.Text);
                    Appointment.Save(SendInvitationsMode.SendToNone);
                }                
4

1 回答 1

1

这在Exchange 2010 SP1中运行良好……我没有Exchange 2007 SP1来测试它。

Appointment appt = new Appointment(service)
{
    Subject = "Next Contact Date",
    Body = new MessageBody()
    {
        BodyType = BodyType.HTML,
        Text = "here is some body content. <b>this is bold</b>" +
              "<table><tr><td><b>Client name: </b></td><td>George</td></tr></table>",
    },
    Start = DateTime.Now.AddDays(1),
    End = DateTime.Now.AddDays(1).AddHours(.5),
};
appt.Save();
于 2012-08-22T16:52:40.403 回答