电子邮件正文格式问题

时间:2011-04-07 01:15:28

标签: c# asp.net email

我的电子邮件格式有问题。我想换一个新的......

这是电子邮件中的格式..

Name: sdds Phone: 343434 Fax: 3434 Email: valencia_arman@yahoo.com 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;

3 个答案:

答案 0 :(得分:4)

如果您是以HTML格式发送,请务必设置格式。

mail.BodyFormat = MailFormat.Html;

然后你可以根据需要使用<br/>

更新:

尝试此选择:

using System.Net.Mail;

...

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

答案 1 :(得分: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("sender@domain.com", "display name");

   message.From = address;
   message.To.Add("to@domain.com");
   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...
   }
}

答案 2 :(得分:0)

您是否尝试过“+ \ n”而不是Environment.NewLine?