2011-04-07 151 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