C#에서 데스크톱 응용 프로그램을 작성하여 가입 된 사용자 집합에 전자 메일 알림을 보냅니다. 나는 Webdav을 사용하여 OWA (Outlook 웹 액세스)을 사용하고 있으며 33 우편까지 모두 작동합니다. 'Operation Timeout' 예외가 발생합니다. 나머지 사용자에게 이메일을 보내도록 신청서를 다시 보낼 수 있지만 예외적으로 몇 가지 이메일을 다시 보낸 후 다시 보낼 수 있습니다. 물론 한 번의 실행으로이 작업을 수행 할 수 있습니다. HttpWebRequest 개체에 일부 시간 제한 값을 추가하고 각 HTTP 요청이 다음 요청을 방해하지 않도록 각 메일을 보낸 후 일부 Thread.Spleep 값을 넣으려고했습니다. 하지만 지금은이 시간 초과 예외와 어떻게 처리 해야할지 모르겠다 붙어있다.WebDav를 사용하여 작업 시간 제한을 throw했습니다.
하나의 아이디어는 내 로그인 한 세션이 만료되었지만 새 이메일을 보낼 때마다 로그인하는 것입니다.
웹 dav를 사용 해본 경험이 있다면 좀 도와주세요.
편집 : 내가 그들을 throught를 반복하고 데이터 테이블 모든 대상 이메일 주소에 넣어 및 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();
// "Mailbox folder where email is being sent from";
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();
//Do the PROPPATCH
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();
//Move File
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)
{
//Log error occurrance
DataLayer.DataLayer.WriteErrorLog("MySource", String.Format("Email sending failed.Exception: {0}",ex.Message), DateTime.Now, destionationEmailAddress,"Failure");
return false;
}
}
갖고있는 코드를 게시 할 수 있습니까? –
나는 나의 질문을 편집하고 내가 그 과정을 수행하기 위해 사용하고있는 방법을 추가했다! – Blerta
해결하셨습니까? 전자 메일을 읽음으로 표시하려고하는 것과 동일한 문제가 발생합니다. 처음 두 개가 처리 된 후 중단되고 시간 초과됩니다. –