Is it
possible to write C# code as below and send email using mnetwork in different country?
MSExchangeWebServiceURL = mail.something.com/ews/exchange.asmx its a web service URL ... sorry to correct my self //....this works great when i run the same code from home network, my friends home network ... anywhere around ... but when i run it from my clients location in columbia ... it fails
I have a valid user name and password on that exchange server. Is there any configuration that I can set to achieve this?
BTW this code below works when I run it within office network and any network within any home network ... i have tried atleast 5 friends network in Plano, Texas. I want this code to work when run from any network in another country.
My client in columbia can connect to web service using a browser .. use the same user name and password ..... but when i run the code above ... it is not able to connect to our web service ....
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);