2017-01-23 18 views
0
//i have left out some parameters for readability 
public static string MailForCandidate(string username, string FromAddr, string ToAddr, string strSubject) 
     { 
      try 
      { 
       MailMessage msg = new MailMessage(); 
       string strMailBody = "Test body"; 

       msg.To = ToAddr; 
       msg.From = FromAddr; 

       msg.BodyFormat = MailFormat.Html; 
       msg.Priority = MailPriority.High; 
       msg.Subject = strSubject; 
       msg.Body = strMailBody.ToString(); 
       SmtpMail.SmtpServer = ConfigurationManager.AppSettings["mailServer"].ToString(); 
       try 
       { 
        SmtpMail.Send(msg); 
        msg = null; 
        return ""; 
       } 
       catch (Exception ex) 
       { 
        Util.Common.LogErrorMessage(ex); 
        msg = null; 
        return username; 
       } 
      } 
      catch (Exception ex) 
      { 
       throw ex; 
      } 
     } 

위의 기능을 사용하여 IIS에서 호스팅되는 .NET 3.5 asp.net 응용 프로그램의 전자 메일을 보내고 있습니다.asp.net에서 system.web.mail을 사용할 때 일부 전자 메일이 지연되거나 배달되지 않습니다.

이메일은 버튼 클릭만으로 전송되며 수신자는 데이터베이스 테이블에서 읽습니다.

내가받는 문제는 일부 수신자는 문제가없는 이메일을 받고, 다른 수신자는 전자 메일을 수신하는 데 너무 오래 걸립니다 (24 시간 후). 참가 예정인 이벤트가 만료되었을 때 (그리고 이것은 우리 회사에게 법적으로 영향을 미친다). 그리고 마침내 다른 사람들은 이메일을 완전히받지 못합니다.

위의 MailForCandidate 기능은 아래 SendCandidateMail에서 호출되고 있습니다.

 private void SendCandidateMail(int intEmailType) 
    { 
     try 
     { 
      ArrayList arrPending = new ArrayList(); 
      ArrayList arrUnsent = new ArrayList(); 
      string strCandidatename = string.Empty; 
      string stractualname = string.Empty; 
      int intUnsentCandCount = 0; 
      if (hdnUnsentNames.Value.Trim() != string.Empty) 
      { 
       arrUnsent.AddRange(hdnUnsentNames.Value.Split(',')); 
      } 
      if (hdnPendingNames.Value.Trim() != string.Empty) 
      { 
       arrPending.AddRange(hdnPendingNames.Value.Split(',')); 
      } 
      hdnUnsentNames.Value = string.Empty; 
      hdnPendingNames.Value = string.Empty; 
      if (!string.IsNullOrEmpty(hdnUnsent.Value) && !string.Empty.Equals(hdnUnsent.Value)) 
      { 
       string[] strUnsIds = hdnUnsent.Value.Split('~'); 
       for (int i = 0; i < strUnsIds.Length; i++) 
       { 
        DataSet dtsetCandidate = CandidatesListBL.GetCandidateDetails(Convert.ToInt32(strUnsIds[i])); 
        stractualname = arrUnsent[i].ToString(); 
        if (dtsetCandidate.Tables[0].Rows.Count > 0) 
        { 
         if (dtsetCandidate.Tables[0].Rows[0]["Time"].ToString() != "0") 
         { 
          //i have left out some parameters for readability 
          strCandidatename = SendMail.MailForCandidate(dtsetCandidate.Tables[0].Rows[0]["User_Id"].ToString(), intEmailType); 
         } 
         else 
          strCandidatename = SendMail.MailForCandidateNoTime(dtsetCandidate.Tables[0].Rows[0]["User_Id"].ToString(), intEmailType); 

         if (strCandidatename.Trim().Equals(string.Empty)) 
         { 
          hdnUnsentNames.Value = hdnUnsentNames.Value + stractualname + ","; 
          intUnsentCandCount = intUnsentCandCount + 1; 

          if (Convert.ToInt32(EnumMaster.EmailType.Customized) != intEmailType) 
          { 
           CandidatesListBL.UpdateCandidateStatus(Convert.ToInt32(strUnsIds[i]), "Sent"); 
           CandidatesListBL.UpdateDateSent(Convert.ToInt32(strUnsIds[i])); 
          } 
         } 
        } 
       } 
       hdnUnsent.Value = string.Empty; 
      } 
     } 
     catch (Exception ex) 
     { 
      WESMessage.DisplayMessage(this, this.UpdatePanel1, DanielHac.TamperProofString.QueryStringEncode("MailFailed"), this.strinfo); 
      Common.LogErrorMessage(ex); 
     } 
    } 

다음은 오류 로그 텍스트 파일에 기록되는 내용입니다.

01/22/2017 3:23:04 PM ==> 예외 메시지 : 스레드가 중단되었습니다. 01/22/2017 3:23:04 PM ==> 예외 소스 : App_Code 예외 대상 사이트 : System.String MailForCandidate (System.String, System.String, System.String, System.Collections.ArrayList, System.String , System.String, System.String, System.String, System.String, UserSession, System.String, System.String, Int32, Int32) 예외 스택 추적 : at WES.Util.SendMail.MailForCandidate (String strUserID, 문자열 사용자 이름, 문자열 암호, 문자열 FromAddr, 문자열 FromAddr, 문자열 ToAddr, 문자열 제목, 문자열 strSubject, 문자열 strCustomMsg, UserSession UserObj, 문자열 strDeadLine, 문자열 strTime, int32 intOfficeId, int32 intMailType) 에서 Pages_ExerciseDetails.SendCandidateMail Int32 intEmailType) 문자열로 예외가 발생했습니다 : System.Threading.ThreadAbortException : 스레드가 중단되었습니다.(문자열 strUserID, 문자열 사용자 이름, 문자열 사용자 이름, 문자열 암호, Pages_ExerciseDetails.SendCandidateMail에서 intOfficeId, INT32 intMailType) (INT32 intEmailType)

그리고

2017년 1월 22일 오후 3시 23분 4초 ==> 예외 메시지 : 스레드가 중단되었습니다. 2017년 1월 22일 오후 3시 23분 4초 ==> 예외 출처 : App_Web_kxc2lbj5 예외 대상 사이트 : 공허 SendCandidateMail (INT32) 예외 스택 추적 : Pages_ExerciseDetails.ibtnSend_Click에서 Pages_ExerciseDetails.SendCandidateMail (INT32 intEmailType) 에서 (개체 보낸 사람 , EventArgs e) 문자열로 예외 : System.Threading.ThreadAbortException : 스레드가 중단되었습니다. Pages_ExerciseDetails.ibtnSend_Click에서 Pages_ExerciseDetails.SendCandidateMail (INT32 intEmailType) (객체 송신자있는 EventArgs E)

2017년 1월 22일 오후 3시 23분 4초 ==> 예외 메시지 또한

에서 : 요청 시간이 초과되었습니다. 101/22/2017 3:23:04 PM ==> 예외 소스 : 예외 대상 사이트 : 예외 스택 추적 : 예외 문자열 : System.Web.HttpException : 요청 시간이 초과되었습니다.

다음

101/22/2017 오후 3시 31분 35초 ==> 예외 메시지 : 유형 'System.Exception'의 예외가 발생했습니다. 2017년 1월 22일 오후 3시 31분 35초 ==> 예외 출처 : App_Web_kxc2lbj5 예외 대상 사이트 : 공허 SendCandidateMail (INT32) 예외 스택 추적 : Pages_ExerciseDetails.SendCandidateMail (INT32 intEmailType) 예외 에서 문자열 : System.Exception : 'System.Exception'유형의 예외가 발생했습니다. Pages_ExerciseDetails.SendCandidateMail (INT32 intEmailType)

에 난 단지 생산에서 발생하고 있기 때문에 하드 troubleshot을 찾을 수 있습니다. QA와 Dev에서 이메일은 동일한 SMTP 서버를 사용하면 문제가 없습니다.

+0

MailForCandidateNoTime과 MailForCandidate의 차이점은 무엇입니까? – Karlta05

+0

메일 본문의 차이점과 다른 중요한 차이점이 없습니다. – StackTrace

+0

system.web.mail이 많은 정보가 없기 때문에 System.Net.Mail 네임 스페이스를 대신 사용해야하는지 궁금합니다. – StackTrace

답변

0

답변으로 내 의견을 게시 할 것입니다.

나는이 쓸모없는 system.web.mail을 그냥 버리는 것으로 해결했습니다. 나는 을 System.Net.Mail &을 사용하여 코드를 다시 작성하면 모든 문제가 해결되고 은 훨씬 빨리 수행됩니다.