2011-04-07 176 views
1

我在電子郵件中的格式有問題。我想有一個新行..電子郵件正文格式問題

這裏的電子郵件格式..

Name: sdds Phone: 343434 Fax: 3434 Email: [email protected] Address: dsds Remarks: dsds Giftwrap: Yes Giftwrap Instructions: sdds Details: PEOPLE OF THE BIBLE(SCPOTB-8101-05) 1 x Php 275.00 = Php 275.00 Total: Php275.00 

這裏是我的C#代碼..

mail.Body = "Name: " + newInfo.ContactPerson + Environment.NewLine 
           + "Phone: " + newInfo.Phone + Environment.NewLine 
           + "Fax: " + newInfo.Fax + Environment.NewLine 
           + "Email: " + newInfo.Email + Environment.NewLine 
           + "Address: " + newInfo.Address + Environment.NewLine 
           + "Remarks: " + newInfo.Notes + Environment.NewLine 
           + "Giftwrap: " + rbGiftWrap.SelectedValue + Environment.NewLine 
           + "Giftwrap Instructions: " + newInfo.Instructions + Environment.NewLine + Environment.NewLine 
           + "Details: " + Environment.NewLine 
           + mailDetails; 
+1

我還在學習,但不會是更好地使用字符串生成器來創建這個字符串? – 2011-04-07 02:06:54

回答

4

如果你在HTML發送它,使它確定你設置了格式。

mail.BodyFormat = MailFormat.Html; 

然後你可以使用<br/>如果你想。

UPDATE:

試試這個作爲一種替代方案:

using System.Net.Mail; 

...

MailMessage myMail; 
myMail = new MailMessage(); 
myMail.IsBodyHtml = true; 
+0

其不工作.. – 2011-04-07 01:29:36

+0

因此,您已將郵件類型設置爲html,並且您將爲每個項目添加
而不是Environment.NewLine?你如何看電子郵件? – Fellmeister 2011-04-07 01:44:04

+0

我在我的郵件中查看過它..我試過你的代碼,並且收到了使用mail.bodyformat = mailformat.html .. – 2011-04-07 01:50:06

0

你嘗試 「+ \ n」,而不是Environment.NewLine?

+0

我試過了..它是一樣的.. :( – 2011-04-07 01:29:00

1

也許你可以試試這個...

我們創建單獨的電子郵件模板(例如EmailTemplate.htm),它包括要發送的消息。消息中的新行不會有問題。

那麼這就是我們的後臺代碼:

private void SendEmail() 
{ 
    string emailPath = "../EmailTemplate.htm"; //Define your template path here 
    string emailBody = string.Empty; 

    StreamReader sr = new StreamReader(emailPath); 

    emailBody = sr.ReadToEnd(); 
    sr.Close(); 
    sr.Dispose(); 

    //Send Email; you can refactor this out 
    MailMessage message = new MailMessage(); 

    MailAddress address = new MailAddress("[email protected]", "display name"); 

    message.From = address; 
    message.To.Add("[email protected]"); 
    message.Subject = "Your Subject"; 
    message.IsBodyHtml = true; //defines that your email is in Html form 
    message.Body = emailBody; 

    //smtp is defined in web.config 
    SmtpClient smtp = new SmtpClient(); 

    try 
    { 
     smtp.Send(message); 
    } 
    catch (Exception ex) 
    { 
     //catch errors here... 
    } 
} 
+0

我完成了..謝謝! – 2011-04-07 03:19:24

+0

對,對我來說太晚了哈哈!:D – KaeL 2011-04-07 03:27:52