2

我的 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;

我应该怎么做才能没有编码问题?

4

1 回答 1

2

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

内容传输编码:base64

据推测,您是在纯文本编辑器中打开邮件,因此电子邮件内容没有被解码。

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

姓名:test tessssst 邮箱:sssssss@mail.ru 电话:89208713061

[au] 选择(信任我)- harvey x mike [au] 选择(信任我)- harvey x mike[au] 选择(信任我)- harvey x mike

于 2013-05-21T13:17:51.373 回答