2011-08-01 3 views
1

smtp를 통해 사내 C# 응용 프로그램에서 개별 eamils를 보낼 때받는 오류 메시지로 고민하고 있습니다. 그것은 윈도우 7에서 잘 작동하지만 우리는 우리의 XP 기계에 다음과 같은 오류 메시지가 나타납니다. Google은 Google 메일 계정과 Google의 smtp.gmail.com 메일 서버를 사용하여 전달합니다. 방화벽이 해제되고 장애가 발생한 시스템에서 McAfee가 비활성화됩니다. 다시 클라이언트 응용 프로그램에 오류 메시지는 다음과 같습니다SMTP sendasync는 Windows 7에서는 작동하지만 XP에서는 실패 함

Error occurred when sending mail to [email protected] System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied. ---> System.Net.Sockets.SocketException: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied 
    at System.Net.Sockets.Socket.BeginReceive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, AsyncCallback callback, Object state) 
    at System.Net.Sockets.NetworkStream.BeginRead(Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state) 
    --- End of inner exception stack trace --- 
    at System.Net.Mail.SmtpConnection.ConnectAndHandshakeAsyncResult.End(IAsyncResult result) 
    at System.Net.Mail.SmtpClient.ConnectCallback(IAsyncResult result) 
    --- End of inner exception stack trace --- 

우리의 C# 코드 그래서 우리는 메일 전송의 결과로 사용자 인터페이스를 업데이트 할 수 있습니다 멀티 스레드됩니다. 메시지를 설정하고 보내려면이 두 가지 방법이 포함 된 메일러 클래스가 있어야합니다.

public void Send() 
    { 
     m_frmAccess.Invoke(m_frmAccess.UpdateDelegate, 
     new Object[] { "" }); 

     SmtpClient client = new SmtpClient("smtp.gmail.com", 587) 
      { 
       Credentials = new NetworkCredential("[email protected]", "xxxxxxxxx"), 
       EnableSsl = true 
      }; 

     try 
     { 
      StringBuilder sb = new StringBuilder(); 
      sb.Append("Message Body"); 
      LinkedResource logo = new LinkedResource("DA-NewBrand-Stack-100px-for.jpg"); 
      logo.ContentId = "companylogo"; 
      htmlView.LinkedResources.Add(logo); 
      m_Errormessage = ""; 
      MailAddress to = new MailAddress(m_To); 
      MailAddress from = new MailAddress(m_From, "Company"); 
      MailAddress cc = new MailAddress("[email protected]", "Name"); 
      MailMessage message = new MailMessage(from, to); 
      message.CC.Add(cc); 
      message.AlternateViews.Add(htmlView); 
      message.IsBodyHtml = true; 
      message.BodyEncoding = System.Text.Encoding.UTF8; 
      message.Subject = m_Subject; 
      client.Timeout = 10000; 
      message.SubjectEncoding = System.Text.Encoding.UTF8; 
      object userState = message; 
      client.SendCompleted += new SendCompletedEventHandler(SmtpClient_OnCompleted); 
      client.SendAsync(message, userState); 

     } 
     catch (Exception ex) 
     { 
      m_Errormessage = ""; 
      m_Errormessage = ex.Message + Environment.NewLine + ex.StackTrace.ToString() + Environment.NewLine +    ex.InnerException + Environment.NewLine; 
      m_frmAccess.Invoke(m_frmAccess.UpdateDelegate, 
      new Object[] { m_Errormessage }); 
     } 

    } 



    public void SmtpClient_OnCompleted(object sender, AsyncCompletedEventArgs e) 
    { 
     //Get the Original MailMessage object 
     m_result = ""; 
     MailMessage mail = (MailMessage)e.UserState; 


     //write out the subject 
     string subject = mail.Subject; 
     try 
     { 
      if (e.Cancelled) 
      { 
       m_result = "Send canceled for message to " + mail.To.ToString(); 
      } 
      if (e.Error != null) 
      { 
       m_result = "Error occurred when sending mail to " + mail.To.ToString() + " " + e.Error.ToString(); 
      } 
      else 
      { 
       m_result = "Message to " + mail.To.ToString() + " was sent."; 
      } 
      m_frmAccess.Invoke(m_frmAccess.UpdateDelegate, 
        new Object[] { m_result }); 

     } 
     catch (Exception ex) 
     { 
      m_result = ex.Message + ex.InnerException.ToString(); 
     } 

    } 

이러한 세 가지 방법은 winform에 있습니다. 내가 선언 형태로

public void UpdateText(string message) 
    { 
     txtMessage.Text = message; 

    } 

    private void ThreadMethod() 
    { 
     clsSmtpEmailer smtpMailer = new clsSmtpEmailer(this); 
     CollectDataToEmail(smtpMailer); 
     smtpMailer.Send(); 
    } 

    private void btnSendEmail_Click(object sender, EventArgs e) 
    { 

     myThread = new Thread(new ThreadStart(ThreadMethod)); 
     myThread.Start(); 

    } 

의 I SMTP 서버에 대한 단지 IP 주소를 사용하여 시도 업데이트 위임

public delegate void UpdateTextCallback(string text); 
    public UpdateTextCallback UpdateDelegate; 

에 대해 다음, 모든 방화벽이 확인하고, 메시지에 SSL을 사용하지 않도록 노력 비활성화하면 모든 바이러스 소프트웨어가 비활성화됩니다. 로컬 XP 시스템에 IIS 용 smtp를 설치했지만 서버로 사용하지 않아서 문제가 해결되지 않았습니다.

앞에서 설명한대로 코드는 Win7에서는 작동하지만 XP에서는 작동하지 않습니다. 이견있는 사람?

+0

Windows XP 서비스 팩이 2라고 가정합니다. – rene

+0

은 Windows XP Enterprise 도메인에 가입되어 있습니까? 권한? Windows 7에서 성능이 향상 되었습니까? 핑 (Ping)이 작동합니까? – rene

답변

0

우리의 솔루션은 Windows XP 시스템을 Windows 7로 업그레이드하는 것입니다. 사용 권한과 관련하여이 두 버전의 Windows간에 smtp 메시지가 전송되는 방식에는 OS 수준 변경이 있어야합니다. 그것은 Win7에서 완벽하게 작동합니다.

관련 문제