1

I searched for a documentation how to add a contact as an attachment to an e-mail generated with the EWS Managed Api 2.2 and because I didn't find a solution online I'd like to share my solution here, because it is quite easy when you found it out.

Zumarta
  • 145
  • 3
  • 18

1 Answers1

1

In an EmailMessage object you can create an new ItemAttachment:

First of all we have to add a contactAttachment to our emailMessage-Object.

ItemAttachment<Contact> contactAttachment = emailMessage.Attachments.AddItemAttachment<Contact>();

Unfortunately we cannot just add the whole contact item to that contactAttachment then, because contactAttachment.Item is read-only.

But we can add all properties one by one to our contactAttachment.Item-object. Here is an example how to add some simple data to it:

contactAttachment.Item.CompanyName = "Company";
contactAttachment.Item.JobTitle = "Software Engineer";
contactAttachment.Item.GivenName = "Fred";

But we also can add physical addresses and contact information that way, for example the E-mail address:

contactAttachment.Item.EmailAddresses[EmailAddressKey.EmailAddress1] =
                "address@test.tld";

So you may fill out all fields which are necessary for you and after sending that message the contact will be attached to that message and you can open and save it in your address book.

Zumarta
  • 145
  • 3
  • 18