If you have a Microsoft Exchange 2007 email server then you have an option to use it's web service direction to send email. The web service itself is a bit strange but we were able to encapsulate the weirdness and make it work just like our SMTP class.
First you would need to make a reference to the exchange web service like this: https://mail.yourwebserver.com/EWS/Services.wsdl
Here is an example:
public bool Send(string From, MailAddress[] To, string Subject, string Body, MailPriority Priority, bool IsBodyHTML, NameValueCollection Headers)
{
// Create a new message.
var message = new MessageType { ToRecipients = new EmailAddressType[To.Length] };
for (int i = 0; i < To.Length; i++)
{
message.ToRecipients[i] = new EmailAddressType { EmailAddress = To[i].Address };
}
// Set the subject and sensitivity properties.
message.Subject = Subject;
message.Sensitivity = SensitivityChoicesType.Normal;
switch (Priority)
{
case MailPriority.High:
message.Importance = ImportanceChoicesType.High;
break;
case MailPriority.Normal:
message.Importance = ImportanceChoicesType.Normal;
break;
case MailPriority.Low:
message.Importance = ImportanceChoicesType.Low;
break;
}
// Set the body property.
message.Body = new BodyType
{
BodyType1 = (IsBodyHTML ? BodyTypeType.HTML : BodyTypeType.Text),
Value = Body
};
var items = new List<ItemType>();
items.Add(message);
// Create a CreateItem request.
var createItem = new CreateItemType()
{
MessageDisposition = MessageDispositionType.SendOnly,
MessageDispositionSpecified = true,
Items = new NonEmptyArrayOfAllItemsType
{
Items = items.ToArray()
}
};
var imp = new ExchangeImpersonationType
{
ConnectingSID = new ConnectingSIDType { PrimarySmtpAddress = From }
};
esb.ExchangeImpersonation = imp;
// Call the CreateItem method and get its response.
CreateItemResponseType response = esb.CreateItem(createItem);
// Get the items returned by CreateItem.
ResponseMessageType[] itemsResp = response.ResponseMessages.Items;
foreach (ResponseMessageType type in itemsResp)
{
if (type.ResponseClass != ResponseClassType.Success)
return false;
}
return true;
}