我的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;
。
如果没有编码问题我该怎么办?
答案 0 :(得分:2)
您所看到的是使用Base-64编码的消息。您可以从电子邮件标题中看到:
Content-Transfer-Encoding:base64
据推测,您是在纯文本编辑器中打开邮件,因此电子邮件内容未被解码。
如果使用Base64 Decoder(任何电子邮件客户端将自动执行此操作)解码邮件,您将获得以下信息:
姓名:test tessssst 电子邮件:sssssss@mail.ru 电话:89208713061
[au]选择(向我倾诉) - harvey x mike [au]选择(信心投入 我) - 哈维x迈克[au]选择(向我倾诉) - 哈维x迈克