static void CreateEmail()
{
// Create service binding.
ExchangeServiceBinding esb = new ExchangeServiceBinding();
esb.Credentials = new NetworkCredential("username", "password", "domain");
esb.Url = @"https://CAS01.example.com/EWS/exchange.asmx";
// Create the CreateItem request.
CreateItemType createItemRequest = new CreateItemType();
// Specifiy how the created items are handled
createItemRequest.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
createItemRequest.MessageDispositionSpecified = true;
// Specify the location of sent items.
createItemRequest.SavedItemFolderId = new TargetFolderIdType();
DistinguishedFolderIdType sentitems = new DistinguishedFolderIdType();
sentitems.Id = DistinguishedFolderIdNameType.sentitems;
createItemRequest.SavedItemFolderId.Item = sentitems;
// Create the array of items.
createItemRequest.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;
// Add the message to the array of items to be created.
createItemRequest.Items.Items = new ItemType[1];
createItemRequest.Items.Items[0] = message;
try
{
// Send the request to create and send the e-mail item, and get the response.
CreateItemResponseType createItemResponse = esb.CreateItem(createItemRequest);
// Determine whether the request was a success.
if (createItemResponse.ResponseMessages.Items[0].ResponseClass == ResponseClassType.Error)
{
throw new Exception(createItemResponse.ResponseMessages.Items[0].MessageText);
}
else
{
Console.WriteLine("Item was created");
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
최근 덧글