我的 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;
。
我应该怎么做才能没有编码问题?