Independentsoft
- any library, any programming language
Home
Purchase
Support
Company
Contact
Exchange Web Services .NET
>
Tutorial
> Create message with custom property
The following example shows you how to create message and set custom property.
C# example
using System; using System.Net; using Independentsoft.Exchange; namespace Sample { class Program { static void Main(string[] args) { NetworkCredential credential = new NetworkCredential("username", "password"); Service service = new Service("https://myserver/ews/Exchange.asmx", credential); try { PropertyName myPropertyName = new PropertyName("MyCustomProperty", StandardPropertySet.PublicStrings, MapiPropertyType.String); ExtendedProperty myProperty = new ExtendedProperty(myPropertyName, "value1"); Message message = new Message(); message.Subject = "Test"; message.Body = new Body("Body text"); message.ToRecipients.Add(new Mailbox("John@mydomain.com")); message.CcRecipients.Add(new Mailbox("Mark@mydomain.com")); message.ExtendedProperties.Add(myProperty); ItemId itemId = service.CreateItem(message); } catch (ServiceRequestException ex) { Console.WriteLine("Error: " + ex.Message); Console.WriteLine("Error: " + ex.XmlMessage); Console.Read(); } catch (WebException ex) { Console.WriteLine("Error: " + ex.Message); Console.Read(); } } } }
VB example
Imports System Imports System.Net Imports Independentsoft.Exchange Namespace Sample Class Module1 Shared Sub Main(ByVal args As String()) Dim credential As New NetworkCredential("username", "password") Dim service As New Service("https://myserver/ews/Exchange.asmx", credential) Try Dim myPropertyName As New PropertyName("MyCustomProperty", StandardPropertySet.PublicStrings, MapiPropertyType.[String]) Dim myProperty As New ExtendedProperty(myPropertyName, "value1") Dim message As New Message() message.Subject = "Test" message.Body = New Body("Body text") message.ToRecipients.Add(New Mailbox("John@mydomain.com")) message.CcRecipients.Add(New Mailbox("Mark@mydomain.com")) message.ExtendedProperties.Add(myProperty) Dim itemId As ItemId = service.CreateItem(message) Catch ex As ServiceRequestException Console.WriteLine("Error: " + ex.Message) Console.WriteLine("Error: " + ex.XmlMessage) Console.Read() Catch ex As WebException Console.WriteLine("Error: " + ex.Message) Console.Read() End Try End Sub End Class End Namespace
Need help? Ask our developers:
Name*
Email*
Message*