2010-01-24 3 views
1

다음 유틸리티 클래스를 사용하여 전자 메일을 보내고 있습니다. 수신자 [email protected]이 존재하지 않거나 전자 메일이 한 가지 이유로 다른 사람에게 도달하지 않으면 내 응용 프로그램을 통보 받다.

smtp 클라이언트가 smtp 서버에 연결하지 못했을 때만 작동합니다.이 경우 예외가 있습니다. 그렇지 않은 경우 전자 메일이 클라이언트에 도달하지 못하는지를 확인하는 유일한 방법은 클라이언트 계정을 확인하는 것입니다.전자 메일이 수신자에게 도착하지 못한 경우를 확인하는 방법

public static class EmailUtil 
    { 
     /// <summary> 
     /// Fires exception if string is null or empty 
     /// </summary> 
     /// <param name="param">param value</param> 
     /// <param name="paramName">is the parameter name to be shown in the exception message</param> 
     private static void CheckStringParam(string parameter, string paramName) 
     { 
      if (String.IsNullOrEmpty(parameter)) 
      { 
       throw new ArgumentException(String.Format("{0} can't be null or empty", paramName)); 
      } 
     } 

     public static void SendEmail(EmailArgument emailArg) 
     { 
      CheckStringParam(emailArg.FromEmail, "emailArg.FromEmail"); 
      CheckStringParam(emailArg.Subject, "emailArg.Subject"); 
      CheckStringParam(emailArg.Body, "emailArg.Body"); 
      string body = emailArg.Body; 

      MailMessage mailMsg = new MailMessage(); 
      mailMsg.From = new MailAddress(emailArg.FromEmail); 

      foreach(string recipient in emailArg.ToEmails) 
      { 
       if (String.IsNullOrEmpty(recipient)) 
       { 
        throw new ArgumentException("One of the values in the emailArg.ToEmails array is null or empty"); 
       } 

       mailMsg.To.Add(new MailAddress(recipient)); 
      } 

      mailMsg.IsBodyHtml = emailArg.IsHtml; 

      if (emailArg.PutHtmlTags) 
      { 
       body = String.Format("{0}" + body + "{1}", "<HTML><Body>", "</Body></HTML>"); 
      } 

      mailMsg.Body = body; 
      mailMsg.BodyEncoding = emailArg.BodyEncoding; 

      // Get client info from the config file , it is tested with Web.config, need to be tested with App.config 
      SMTPConfiguration smtpConfig = (SMTPConfiguration)System.Configuration.ConfigurationManager.GetSection("SMTPConfigurationGroup/SMTPServer"); 

      SmtpClient client = new SmtpClient(smtpConfig.Host, smtpConfig.Port); 
      client.EnableSsl = smtpConfig.EnableSSL; 
      client.Credentials = new System.Net.NetworkCredential(smtpConfig.Username, smtpConfig.Password); 



      // The notifications of failure are sent only to the client email. 
      // Exceptions are not guranteed to fire if the Receiver is invalid; for example gmail smtp server will fire exception only when [email protected] is not there. 
      // Exceptions will be fired if the server itself timeout or does not responding (due to connection or port problem, extra). 
      mailMsg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure; 

      client.Send(mailMsg);    
     } 


    } 

답변

7

SMTP는 '최선형'전송입니다. SMTP 서버에 메시지를 보내면 대상에 도착했는지 여부를 알 수 없습니다 (길에 연결 문제가있는 경우 며칠이 걸릴 수 있습니다). 전송이 실패한 방식으로 일부 SMTP 서버에서 이메일을받을 수 있습니다 (아마도 며칠 후).

메시지를 수신했음을 나타내는 메시지 헤더를 추가하더라도 클라이언트는 해당 알림을 보내지 않도록 구성하거나 지시 할 수 있습니다.

+0

주소를 기반으로 오류 코드를 반환하기 위해 프로토콜을 사용할 수있는 방법이 있는지 궁금합니다. – IrishChieftain

+1

@IrishChieftain : 연결할 서버가 모를 가능성이 있습니다. 그것을 알기 위해서는 이메일 주소가있는 도메인의 SMTP 서버에 연결해야합니다. 그렇더라도 주소가 유효한지 서버가 알 수있는 것은 아닙니다. SMTP는 서버가 대상에 대한 모든 것을 알지 못하는 상태에서 작동하도록 설계되었습니다. 단지 더 많이 알아야하는 것으로 전달하기에 충분할 필요가 있습니다. –

+0

그리고 대부분의 서버는 특정 SMTP 서버에서 주소가 유효하지 않은 것으로 알려진 경우에도 "OK"를 반환합니다. 또한 스팸에 대한 제한된 대응책이기도합니다. – JasonTrue

2

Web beacon은 전자 메일 추적을위한 가장 일반적인 도구입니다. 일반적으로 전자 메일 메시지의 HTML에 포함 된 작은 투명 이미지 1px x 1px입니다. embeded는 img 태그를 의미합니다 - 여기에 예제가 있습니다 : <img src="www.somedomainhere.com/someimge.gif?[tracking_code]" />. 그런 다음 모든 요청을 해당 이미지에 기록 할 수 있습니다. 이 방법은 사용자가 HTML 형식의 메시지를 읽을 수있는 경우에만 작동합니다.

+2

및 클라이언트가 다운로드합니다 (Outlook은 기본적으로 Outlook이 아니며 야후도 지원하지 않습니다) – dkackman

+0

Oho ... 새롭고 멋진 것입니다. –

+1

HTML을 허용하더라도 대부분의 이메일 클라이언트는 명시 적 권한을 부여 할 때까지 외부 링크 이미지를 차단합니다. 스팸 발송자가 전자 메일 주소 대상을 확인하는 데 주로 악용 한 덕분입니다. – JasonTrue

관련 문제