CreateItemType 类

定义

CreateItemType 表示创建项或响应对象的请求。

public ref class CreateItemType : ExchangeWebServices::BaseRequestType
public class CreateItemType : ExchangeWebServices.BaseRequestType
Public Class CreateItemType
Inherits BaseRequestType
继承
CreateItemType

示例

下面的代码示例演示一个 CreateItem 请求,该请求创建一封电子邮件,将其发送给多个收件人,并将其副本保存在“已发送邮件”默认文件夹中。

static void CreateEmail()
{
    // Create the CreateItem request.
    CreateItemType createEmailRequest = new CreateItemType();

    // Specifiy how the e-mail will be handled.
    createEmailRequest.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
    createEmailRequest.MessageDispositionSpecified = true;

    // Specify the location of sent items.
    createEmailRequest.SavedItemFolderId = new TargetFolderIdType();
    DistinguishedFolderIdType sentitems = new DistinguishedFolderIdType();
    sentitems.Id = DistinguishedFolderIdNameType.sentitems;
    createEmailRequest.SavedItemFolderId.Item = sentitems;

    // Create the array of items.
    createEmailRequest.Items = new NonEmptyArrayOfAllItemsType();

    // Create a single e-mail message.
    MessageType message = new MessageType();
    message.Subject = "Daily Report";
    message.Body = new BodyType();
    message.Body.BodyType1 = BodyTypeType.Text;
    message.Body.Value = "(1) Handled customer issues, (2) Saved the world.";
    message.ItemClass = "IPM.Note";
    message.Sender = new SingleRecipientType();
    message.Sender.Item = new EmailAddressType();
    message.Sender.Item.EmailAddress = "user1@example.com";
    message.ToRecipients = new EmailAddressType[1];
    message.ToRecipients[0] = new EmailAddressType();
    message.ToRecipients[0].EmailAddress = "user2@example.com";
    message.Sensitivity = SensitivityChoicesType.Normal;
    message.SensitivitySpecified = true;
    message.Importance = ImportanceChoicesType.High;
    message.ImportanceSpecified = true;

    // Add the message to the array of items to be created.
    createEmailRequest.Items.Items = new ItemType[1];
    createEmailRequest.Items.Items[0] = message;

    try
    {
        // Create the service binding.
        // Identify the service and the user.
        ExchangeServiceBinding esb = new ExchangeServiceBinding();
        esb.Credentials = new NetworkCredential("username", "password", "domain");
        esb.Url = @"https://ExchangeServer.com/EWS/Exchange.asmx";

        // Send a CreateItem request and get the CreateItem response.
        CreateItemResponseType createItemResponse = esb.CreateItem(createEmailRequest);
        ArrayOfResponseMessagesType responseMessages = createItemResponse.ResponseMessages;

        // Access the response message.
        ResponseMessageType responseMessage = responseMessages.Items[0];
        // Determine whether the request was a success.
        if (responseMessages.Items[0].ResponseClass == ResponseClassType.Error)
        {
            throw new Exception(responseMessages.Items[0].MessageText);
        }
        if (responseMessage is ItemInfoResponseMessageType)
        {
            ItemInfoResponseMessageType createItemResp = (responseMessage as ItemInfoResponseMessageType);
            ArrayOfRealItemsType aorit = createItemResp.Items;

            // Determine whether there are items in response.
            if (aorit.Items != null)
            {
                foreach (ItemType item in aorit.Items)
                {
                    if (item is ItemType)
                    {
                        ItemType myItem = (item as ItemType);
                    }
                    if (item is MessageType)
                    {
                        MessageType myMessage = (item as MessageType);
                    }
                    // TODO: Add logic to check and cast for all other types.
                }
            }
        }
        else
        {
            Console.WriteLine("Item(s) created");
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

注解

CreateItemType用于在 Exchange 数据库中创建响应对象和项。 下表描述了可以使用 创建的 CreateItemType项和响应对象。

ItemType 表示在 Exchange 数据库中创建的泛型项。
MessageType 表示将在 Exchange 数据库中创建的电子邮件。
TaskType 表示在 Exchange 数据库中创建的任务。
ContactItemType 表示将在 Exchange 数据库中创建的联系人项。
CalendarItemType 表示在 Exchange 数据库中创建的日历条目。
AcceptItemType 表示用于接受会议邀请的响应对象。
CancelCalendarItemType 表示用于取消日历项的响应对象。
DeclineItemType 表示拒绝会议邀请的响应对象。
ForwardItemType 表示用于将项目转发给其他用户的响应对象。
RemoveItemType 表示用于从日历中删除已取消的会议的响应对象。
ReplyAllToItemType 表示答复项目的所有收件人的响应对象。
ReplyToItemType 表示用于答复项目发件人的响应对象。
TentativelyAcceptItemType 表示用于暂时接受会议邀请的响应对象。
SuppressReadReceiptType 表示用于禁止显示已读回执的响应对象。

注意CreateItemType 不能用于创建通讯组列表、会议消息、会议请求消息、会议响应消息和会议取消消息。

构造函数

CreateItemType()

构造 CreateItemType 函数初始化 类的新实例 CreateItemType

属性

Items

属性 Items 获取或设置要创建的项的集合。

MessageDisposition

属性 MessageDisposition 获取或设置一个枚举,该枚举描述在创建项后如何处理它。 电子邮件需要此属性。

MessageDispositionSpecified

属性 MessageDispositionSpecified 获取或设置一个布尔值,该值指定属性是否 MessageDisposition 序列化为简单对象访问协议 (SOAP) 请求。

SavedItemFolderId

属性 SavedItemFolderId 获取或设置保存新项目的文件夹。

SendMeetingInvitations

属性 SendMeetingInvitations 获取或设置一个枚举,该枚举描述创建会议请求后如何处理这些请求。 此属性对于日历项是必需的。

SendMeetingInvitationsSpecified

属性 SendMeetingInvitationsSpecified 获取或设置一个布尔值,该值指定是否 SendMeetingInvitations 序列化为简单对象访问协议 (SOAP) 请求。

适用于