2
我在我的mvc網站上有反饋表格,我需要將此表格發送至電子郵件。
我想測試我的形式,所以我對象MAILMESSAGE保存到磁盤爲* .eml文件asp.net mvc來自網站編碼的4個字母
[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("[email protected]");
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" <[email protected]>
X-Receiver: [email protected]
MIME-Version: 1.0
From: "Letter from site" <[email protected]>
To: [email protected]
Date: 21 May 2013 16:57:55 +0400
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
TmFtZTogdGVzdCB0ZXNzc3NzdApFbWFpbDogc3Nzc3Nzc0BtYWlsLnJ1ClBob25lOiA4
OTIwODcxMzA2MQoKW2F1XSBDaG9pY2VzIChjb25maWRlIGluIG1lKSAtIGhhcnZleSB4
IG1pa2UgW2F1XSBDaG9pY2VzIChjb25maWRlIGluIG1lKSAtIGhhcnZleSB4IG1pa2Vb
YXVdIENob2ljZXMgKGNvbmZpZGUgaW4gbWUpIC0gaGFydmV5IHggbWlrZQ==
爲什麼信的機身看起來那樣?
我將用英語和俄語發送網站信件,並設置。
我應該怎麼做才能避免編碼問題?
因此,當我將表單發送至電子郵件時,我不會遇到編碼問題,對吧? – Heidel
不,這是一個非常典型的電子郵件格式,並且會被任何電子郵件客戶端自動解碼。 –
很好,謝謝你。但是爲什麼我的''n「'代碼在信件的身體不工作? – Heidel