电子邮件正文格式问题
本文关键字:问题 格式 正文 电子邮件 | 更新日期: 2023-09-27 17:48:57
我的电子邮件格式有问题。我想有一个新的行
这是电子邮件的格式…
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;
如果你用HTML发送,确保你设置了格式。
mail.BodyFormat = MailFormat.Html;
然后你可以使用<br/>
如果你想。
试试下面的选项:
using System.Net.Mail;
…
MailMessage myMail;
myMail = new MailMessage();
myMail.IsBodyHtml = true;
也许你可以试试这个…
我们创建单独的电子邮件模板(例如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...
}
}
你试过用"+'n"代替Environment.NewLine吗?