我有以下字符串,我需要用於確認電子郵件地址。這是西班牙語翻譯,當在Web客戶端中查看時導致問題。如下所示。電子郵件地址編碼問題
model.FromAddresses = new EmailAddress
{
Address = fromAddressComponents[0],
DisplayName = fromAddressComponents[1]
};
值從資源串採取以下
<data name="BookingConfirmation_FromAddress" xml:space="preserve">
<value>Confirmació[email protected]</value>
</data>
顯示在電子郵件客戶端的值變爲(應該是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();
}
}
謝謝但我試過ECNcode /解碼但它不起作用 – 2012-07-24 08:15:08
你可以顯示代碼如何從資源字符串中獲取價值? – 2012-07-24 08:27:28
這實際上是一個有效的電子郵件地址嗎? – 2012-07-24 08:29:54