1: // Setup the request
2: MessageType emailMessage = new MessageType();
3:
4: // Set the To email address
5: emailMessage.ToRecipients = new EmailAddressType[1];
6: emailMessage.ToRecipients[0] = new EmailAddressType();
7: emailMessage.ToRecipients[0].EmailAddress = "email@receiver.somewhere";
8:
9: // Set the From email address
10: emailMessage.From = new SingleRecipientType();
11: emailMessage.From.Item = new EmailAddressType();
12: emailMessage.From.Item.EmailAddress = "email@sender.somewhere";
13:
14: // Set the Subject
15: emailMessage.Subject = this.textBoxSubject.Text;
16:
17: // Set the Body
18: emailMessage.Body = new BodyType();
19: emailMessage.Body.BodyType1 = BodyTypeType.Text;
20: emailMessage.Body.Value = "Something to write about";
21:
22:
23: // Create request object and set properties
24:
25: // Create the CreateItemType in order to create and send the email
26: CreateItemType request = new CreateItemType();
27: request.Items = new NonEmptyArrayOfAllItemsType();
28: request.Items.Items = new ItemType[1];
29: request.Items.Items[0] = emailMessage;
30: request.MessageDisposition = MessageDispositionType.SendAndSaveCopy;
31: request.MessageDispositionSpecified = true;
32:
33:
34: // Call CreateItem and process response
35:
36: // Finally, call the CreateItem method to create and send the email
37: CreateItemResponseType response = _service.CreateItem(request);
38:
39: // Analyze the response message for success/failure
40: ItemInfoResponseMessageType responseMessage = response.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
41:
42: if (responseMessage.ResponseClass == ResponseClassType.Success)
43: success = true;
44:
45: MessageBox.Show("Email send succeeded: " + success);