How to send an email using Exchange Webservice

public bool SendEmail(
String sUserName,
String sPassword,
String sDomain,
String sSubject,
String sBodyText,
String sRecipients)
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
service.Credentials = new WebCredentials(sUserName, sPassword, sDomain);
service.TraceEnabled = true;
/* Discover the Exchange server based on this user */
/* I couldn't get this to work with the Elmstone network */
service.AutodiscoverUrl(sUserName + "@" + sDomain);
//service.Url = new Uri("https://myserver.mydomain.local/EWS/Exchange.asmx");

// Create the e-mail message, set its properties, and send it to, saving a copy to the Sent Items folder.
EmailMessage message = new EmailMessage(service);
message.Subject = sSubject;
message.Body = sBodyText;
string[] myRecipients = sRecipients.Split(';');
foreach(string myRecipient in myRecipients)
/* Send and save a copy to the default location (most likely sent items) */
return true;


Popular posts from this blog

Windows Server and the Task Scheduler Error Code 0x3

The living wage failure

IDE's and speed