I am creating a C # desktop application to send email notifications to a set of subscribers. I use Webdav to implement this feature and using OWA(access to the Outlook website) and everything works fine until message 33 "Operation timeout" is sent. I can restart my application to send emails to other users, but again after some emails appear again. Of course, I could complete this operation in one go. I tried to add some timeout value to my HttpWebRequest object, and also put some Thread.Spleep value after sending every mail so that every HTTP request would not interfere with the next request. But now Iβm stuck in this timeout exception and donβt know how to deal with it.
One idea would be that my session in owa has expired, but I register every time I send a new message.
Please can you help me if you come across web dav.
Edit: after entering the data of all the email addresses of the final address, I scroll through them and calling this method to send email using webdav
private bool SendingEmailWithDavAttachment(string subject, string body, string destionationEmailAddress, string filePath)
{
try
{
System.Net.HttpWebRequest PUTRequest;
System.Net.HttpWebRequest PUTRequest1;
System.Net.WebResponse PUTResponse;
System.Net.WebResponse PUTResponse1;
System.Net.HttpWebRequest PROPPATCHRequest;
System.Net.WebResponse PROPPATCHResponse;
System.Net.HttpWebRequest MOVERequest;
System.Net.WebResponse MOVEResponse;
System.Net.CredentialCache MyCredentialCache;
string strMailboxURI = "";
string strSubURI = "";
string strTempURI = "";
string strServer = ConfigurationSettings.AppSettings["MailServer"].ToString();
string strPassword = ConfigurationSettings.AppSettings["EmailPassword"].ToString();
string strAlias = ConfigurationSettings.AppSettings["EmailUsername"].ToString();
string strTo = destionationEmailAddress;
string strSubject = subject;
string strBody = "";
byte[] bytes = null;
System.IO.Stream PUTRequestStream = null;
System.IO.Stream PROPPATCHRequestStream = null;
System.IO.Stream PUTRequestStream1 = null;
strMailboxURI = "http://" + strServer + "/exchange/" + strAlias;
strSubURI = "http://" + strServer + "/exchange/" + strAlias + "/##DavMailSubmissionURI##/";
strTempURI = "http://" + strServer + "/exchange/" + strAlias + "/drafts/" + strSubject + ".eml/";
strBody = "To: " + strTo + "\n";
strBody += "Subject: " + strSubject + "\n" +
"Date: " + System.DateTime.Now +
"X-Mailer: test mailer" + "\n" +
"MIME-Version: 1.0" + "\n" +
"Content-Type: text/html;" + "\n" +
"Charset = \"iso-8859-1\"" + "\n" +
"\n" + body;
MyCredentialCache = new System.Net.CredentialCache();
MyCredentialCache.Add(new System.Uri(strMailboxURI), "Basic", new System.Net.NetworkCredential(strAlias, strPassword));
PUTRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strTempURI);
PUTRequest.Credentials = MyCredentialCache;
PUTRequest.Method = "PUT";
bytes = Encoding.UTF8.GetBytes((string)strBody);
PUTRequest.ContentLength = bytes.Length;
PUTRequestStream = PUTRequest.GetRequestStream();
PUTRequestStream.Write(bytes, 0, bytes.Length);
PUTRequestStream.Close();
PUTRequest.ContentType = "message/rfc822";
PUTRequest.KeepAlive = true;
PUTResponse = (System.Net.HttpWebResponse)PUTRequest.GetResponse();
string strxml = "<?xml version='1.0'?>" +
"<d:propertyupdate xmlns:d='DAV:'>" +
"<d:set>" +
"<d:prop>" +
"<isCollection xmlns='DAV:'>False</isCollection>" +
"</d:prop>" +
"</d:set>" +
"</d:propertyupdate>";
PROPPATCHRequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strTempURI);
PROPPATCHRequest.KeepAlive = true;
PROPPATCHRequest.Credentials = MyCredentialCache;
PROPPATCHRequest.Headers.Set("Translate", "f");
PROPPATCHRequest.ContentType = "text/xml";
PROPPATCHRequest.ContentLength = strxml.Length;
PROPPATCHRequest.Method = "PROPPATCH";
byte[] PROPPATCHbytes = Encoding.UTF8.GetBytes(strxml);
PROPPATCHRequest.ContentLength = PROPPATCHbytes.Length;
PROPPATCHRequestStream = PROPPATCHRequest.GetRequestStream();
PROPPATCHRequestStream.Write(PROPPATCHbytes, 0, PROPPATCHbytes.Length);
PROPPATCHRequestStream.Close();
PROPPATCHResponse = (System.Net.HttpWebResponse)PROPPATCHRequest.GetResponse();
string fileName = path.Substring(path.LastIndexOf("\\") + 1);
string attachURI = strTempURI + fileName;
PUTRequest1 = (System.Net.HttpWebRequest)HttpWebRequest.Create(attachURI);
PUTRequest1.Credentials = MyCredentialCache;
PUTRequest1.Method = "PUT";
PUTRequest1.KeepAlive = true;
System.IO.FileStream inFile;
byte[] binaryData;
inFile = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
binaryData = new Byte[inFile.Length];
long bytesRead = inFile.Read(binaryData, 0, (int)inFile.Length);
inFile.Close();
PUTRequest1.ContentLength = binaryData.Length;
PUTRequestStream1 = PUTRequest1.GetRequestStream();
PUTRequestStream1.Write(binaryData, 0, binaryData.Length);
PUTRequestStream1.Close();
PUTResponse1 = (System.Net.HttpWebResponse)PUTRequest1.GetResponse();
MOVERequest = (System.Net.HttpWebRequest)HttpWebRequest.Create(strTempURI);
MOVERequest.Credentials = MyCredentialCache;
MOVERequest.Method = "MOVE";
MOVERequest.Headers.Add("Destination", strSubURI);
MOVEResponse = (System.Net.HttpWebResponse)MOVERequest.GetResponse();
return true;
}
catch (Exception ex)
{
DataLayer.DataLayer.WriteErrorLog("MySource", String.Format("Email sending failed.Exception: {0}",ex.Message ), DateTime.Now, destionationEmailAddress,"Failure");
return false;
}
}
source
share