Is it possible to wrtie C# code as below .. and send email using my
home network.
I have a valid user name and password on that exchange server. Is there any configuration that i can set to achieve this.
BY THE WAY ... this code blow works when i run it within office network .... i want this code to work when run from any network ....
Thank you for your help guys ...
String cMSExchangeWebServiceURL = (String)System.Configuration.ConfigurationSettings.AppSettings["MSExchangeWebServiceURL"];
String cEmail = (String)System.Configuration.ConfigurationSettings.AppSettings["Cemail"];
String cPassword = (String)System.Configuration.ConfigurationSettings.AppSettings["Cpassword"];
String cTo = (String)System.Configuration.ConfigurationSettings.AppSettings["CTo"];
ExchangeServiceBinding esb = new ExchangeServiceBinding();
esb.Timeout = 1800000;
esb.AllowAutoRedirect = true;
esb.UseDefaultCredentials = false;
esb.Credentials = new NetworkCredential(cEmail, cPassword);
esb.Url = cMSExchangeWebServiceURL;
ServicePointManager.ServerCertificateValidationCallback += delegate(object sender1, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true; };
// Create a CreateItem request object
CreateItemType request = new CreateItemType();
// Setup the request:
// Indicate that we only want to send the message. No copy will be saved.
request.MessageDisposition = MessageDispositionType.SendOnly;
request.MessageDispositionSpecified = true;
// Create a message object and set its properties
MessageType message = new MessageType();
message.Subject = subject;
message.Body = new TestOutgoingEmailServer.com.cogniti.mail1.BodyType();
message.Body.BodyType1 = BodyTypeType.HTML;
message.Body.Value = body;
message.ToRecipients = new EmailAddressType[3];
message.ToRecipients[0] = new EmailAddressType();
//message.ToRecipients[1] = new EmailAddressType();
//message.ToRecipients[2] = new EmailAddressType();
message.ToRecipients[0].EmailAddress = "
[email protected]";
message.ToRecipients[0].RoutingType = "SMTP";
//message.CcRecipients = new EmailAddressType[1];
//message.CcRecipients[0] = new EmailAddressType();
//message.CcRecipients[0].EmailAddress = toEmailAddress.ElementAt(1).ToString();
//message.CcRecipients[0].RoutingType = "SMTP";
//There are some more properties in MessageType object
//you can set all according to your requirement
// Construct the array of items to send
request.Items = new NonEmptyArrayOfAllItemsType();
request.Items.Items = new ItemType[1];
request.Items.Items[0] = message;
// Call the CreateItem EWS method.
CreateItemResponseType response = esb.CreateItem(request);