gpt4 book ai didi

c# - asp.net mvc 4 来自站点编码的字母

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:55 24 4
gpt4 key购买 nike

我的 mvc 站点上有反馈表,我需要将此表发送到电子邮件。
我想测试我的表单,所以我将 MailMessage 对象作为 *.eml 文件保存到磁盘

[HttpGet]
public ActionResult Contacts()
{
FeedbackForm temp = new FeedbackForm();
temp.Message = @Resources.Global.Contacts_Form_Message_Field;
return View(temp);
}

[HttpPost]
public ActionResult Contacts(FeedbackForm Model)
{
MailMessage msg = new MailMessage();
msg.BodyEncoding = Encoding.UTF8;
msg.From = new MailAddress(Model.Email,
@Resources.Global.Contacts_Form_Email_Title);
msg.To.Add("tayna-anita@mail.ru");

string message = @Resources.Global.Contacts_Form_Name_Field + ": "
+ Model.Name + "\n"
+ "Email: " + Model.Email + "\n"
+ @Resources.Global.Contacts_Form_Phone_Field + ": "
+ Model.Phone + "\n\n"
+ Model.Message;
msg.Body = message;
msg.IsBodyHtml = false;

SmtpClient client = new SmtpClient("mysmtphost");
client.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
client.PickupDirectoryLocation = @"C:\test";

try
{
client.Send(msg);
}
catch (Exception ex)
{
}

FeedbackForm tempForm = new FeedbackForm();
tempForm.Message = @Resources.Global.Contacts_Form_Message_Field;

return View(tempForm);
}

我得到:

 X-Sender: "Letter from site" <sssssss@mail.ru>  
X-Receiver: tayna-anita@mail.ru
MIME-Version: 1.0
From: "Letter from site" <sssssss@mail.ru>
To: tayna-anita@mail.ru
Date: 21 May 2013 16:57:55 +0400
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

TmFtZTogdGVzdCB0ZXNzc3NzdApFbWFpbDogc3Nzc3Nzc0BtYWlsLnJ1ClBob25lOiA4
OTIwODcxMzA2MQoKW2F1XSBDaG9pY2VzIChjb25maWRlIGluIG1lKSAtIGhhcnZleSB4
IG1pa2UgW2F1XSBDaG9pY2VzIChjb25maWRlIGluIG1lKSAtIGhhcnZleSB4IG1pa2Vb
YXVdIENob2ljZXMgKGNvbmZpZGUgaW4gbWUpIC0gaGFydmV5IHggbWlrZQ==

为什么信的正文是那样的?

我将从站点用英语和俄语发送信件,并且我设置了 msg.BodyEncoding = Encoding.UTF8;

我应该怎么做才能避免编码问题?

最佳答案

您看到的是一条用 Base-64 编码的消息。您可以从电子邮件标题中看到这一点:

Content-Transfer-Encoding: base64

假设您是在纯文本编辑器中打开邮件,因此电子邮件内容未被解码。

如果您使用 Base64 Decoder 解码消息(任何电子邮件客户端都会自动执行),您将获得以下信息:

Name: test tessssst Email: sssssss@mail.ru Phone: 89208713061

[au] Choices (confide in me) - harvey x mike [au] Choices (confide in me) - harvey x mike[au] Choices (confide in me) - harvey x mike

关于c# - asp.net mvc 4 来自站点编码的字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16670871/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com