2012-07-24 2 views
4

'보낸 사람'확인 전자 메일 주소로 사용해야하는 다음 문자열이 있습니다. 이것은 웹 클라이언트에서 볼 때 문제를 일으키는 스페인어 번역입니다. 아래에 표시됩니다. 값이된다 이메일 클라이언트 내에서전자 메일 주소 인코딩 문제

<data name="BookingConfirmation_FromAddress" xml:space="preserve"> 
    <value>Confirmació[email protected]</value> 
    </data> 

아래와 같이 리소스 문자열에서 촬영

model.FromAddresses = new EmailAddress 
{ 
    Address = fromAddressComponents[0], 
    DisplayName = fromAddressComponents[1] 
}; 

값은, (Confirmació[email protected]을해야한다)

=?utf-8?Q?Confirmaci=C3=B3n 

를 어떻게 볼 수 이걸 피하려면? 나는 그것 때문에 알지만, 나는이 문제를 피하는 방법을 모르겠습니다!

감사합니다,

UPDATE

전체 코드 아래 제임스 :

public void Send(MailAddress to, MailAddress from, string subject, string body) 
    { 
     var message = new MailMessage 
          { 
           BodyEncoding = new System.Text.UTF8Encoding(true), 
           From = from, 
           Subject = subject, 
           Body = body, 
           IsBodyHtml = true 
          }; 


     message.To.Add(to.Address); 

     var smtp = new SmtpClient() { Timeout = 100000 }; 
     try 
     { 
      smtp.Send(message); 
     } 
     finally 
     { 
      if (smtp.DeliveryMethod == SmtpDeliveryMethod.Network) 
       smtp.Dispose(); 
     } 

    } 





// New Version 
// -------------------------- 


    public override void Handle(SendEmailEmailCommand emailCommand) 
    { 
     if(!_config.SendEmail) 
     { 
      return; 
     } 

     var to = new MailAddress(emailCommand.To.Address, emailCommand.To.DisplayName); 
     var from = new MailAddress(emailCommand.From.Address, Uri.UnescapeDataString(emailCommand.From.DisplayName)); 

     try 
     { 
      var msgBody = _compressor.Decompress(emailCommand.Body); 
      _emailClient.Send(to, from, emailCommand.Subject, msgBody); 
     }  
     catch (Exception ex) 
     { 
      _logger.Error("An error occurred when trying to send an email", ex); 
      throw; 
     } 
    } 



    public void Send(MailAddress to, MailAddress from, string subject, string body) 
    { 
     var message = new MailMessage 
          { 
           BodyEncoding = new System.Text.UTF8Encoding(true), 
           From = from, 
           Subject = subject, 
           Body = body, 
           IsBodyHtml = true 
          }; 


     message.To.Add(to.Address); 

     if (!string.IsNullOrWhiteSpace(_config.BccEmailRecipents)) 
     { 
      message.Bcc.Add(_config.BccEmailRecipents); 
     } 


     SendEmail(message); 

     if (_config.BackupEmailsEnabled) 
     { 
      SendBackupEmail(message); 
     } 
    } 



    private void SendEmail(MailMessage message) 
    { 
     var smtp = new SmtpClient() { Timeout = 100000 }; 
     try 
     { 
      smtp.Send(message); 
     } 
     finally 
     { 
      if (smtp.DeliveryMethod == SmtpDeliveryMethod.Network) 
       smtp.Dispose(); 
     } 
    } 
+0

감사합니다. ecncode/decode를 시도했지만 작동하지 않았습니다. –

+0

리소스 문자열에서 값을 가져 오는 방법을 코드에 표시 할 수 있습니까 ??? –

+0

실제로 유효한 전자 메일 주소입니까? –

답변

3

System.Uri 클래스 메소드를 사용하여 아래의 예를보고하십시오, 그것은 당신에게

string email = "Confirmació[email protected]"; 

string escaped = 
     System.Uri.EscapeDataString(email); // Confirmaci%C3%B3n%40test.com 
string unescaped = 
     System.Uri.UnescapeDataString(email); //Confirmació[email protected] 
도움이되기를 바랍니다
+0

런타임에 다음 오류 메시지가 나타납니다 (EscapeDataString과 UnescapeDataString을 모두 시도했습니다) : "지정한 문자열이 전자 메일 주소에 필요한 양식에 없습니다." –

+0

Mr Radford 제게 불쾌한 코드를 보여주세요. – HatSoft

+0

@JamesRadford 당신이 그것을이 방법으로 사용하고 계십니까? System.Uri.method (email); – HatSoft