/// <remarks/> public void CreateItemAsync(CreateItemType CreateItem1, object userState) { if ((this.CreateItemOperationCompleted == null)) { this.CreateItemOperationCompleted = new System.Threading.SendOrPostCallback(this.OnCreateItemOperationCompleted); } this.InvokeAsync("CreateItem", new object[] { CreateItem1}, this.CreateItemOperationCompleted, userState); }
public bool SendMailExchange(string recipientEmail, string subjectName, string bodyVal, string replyTo) { string senderEmail = userName + "@4s.saic.com.cn"; SetCertificatePolicy(); ExchangeServiceBinding esb = new ExchangeServiceBinding(); esb.Credentials = new NetworkCredential(userName, userPassword, domainName); esb.Url = "https://10.166.1.32/ews/exchange.asmx"; 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 = subjectName; message.Body = new BodyType(); message.Body.BodyType1 = BodyTypeType.HTML; message.Body.Value = bodyVal; message.ItemClass = "IPM.Note"; message.Sender = new SingleRecipientType(); message.Sender.Item = new EmailAddressType(); message.Sender.Item.EmailAddress = senderEmail; message.ToRecipients = new EmailAddressType[1]; message.ToRecipients[0] = new EmailAddressType(); message.ToRecipients[0].EmailAddress = recipientEmail; if (!string.IsNullOrWhiteSpace(recipientEmail)) { string[] val = recipientEmail.Split(','); int replyCount = val.Length; message.ToRecipients = new EmailAddressType[replyCount]; for (int i = 0; i < replyCount; i++) { message.ToRecipients[i] = new EmailAddressType(); message.ToRecipients[i].EmailAddress = val[i]; } } message.Sensitivity = SensitivityChoicesType.Normal; if (!string.IsNullOrWhiteSpace(replyTo)) { string[] val = replyTo.Split(','); int replyCount = val.Length; message.ReplyTo = new EmailAddressType[replyCount]; for (int i = 0; i < replyCount; i++) { message.ReplyTo[i] = new EmailAddressType(); message.ReplyTo[i].EmailAddress = val[i]; } } // 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); return false; } else { return true; } } catch (Exception ex) { Console.WriteLine(ex.Message); return false; } }
/// <remarks/> public void CreateItemAsync(CreateItemType CreateItem1) { this.CreateItemAsync(CreateItem1, null); }