我通过下面定义的课程发送电子邮件。这工作好几年但最近我做了一个小改动(改变了我设置主机的方式和代码中显示的端口:smtpClient.Port和smtpClient.Host)。 我不确定这是不是巧合现在我的新行不再包含在发送的消息中。 整个邮件作为一行到达。有没有人知道我怎么解决这个问题?
public class Email
{
private string from;
private string to;
private string cc = null;
private string bcc;
private string subject;
private string body;
private string displayname;
public string From
{
get { return from; }
set { from = value; }
}
public string To
{
get { return to; }
set { to = value; }
}
public string Cc
{
get { return cc; }
set { cc = value; }
}
public string Bcc
{
get { return bcc; }
set { bcc = value; }
}
public string Subject
{
get { return subject; }
set { subject = value; }
}
public string Body
{
get { return body; }
set { body = value; }
}
public string DisplayName
{
get { return displayname; }
set { displayname = value; }
}
public void Send()
{
MailMessage message = new MailMessage();
message.From = new MailAddress(from);
message.To.Add(new MailAddress(to));
message.Body = body;
message.Subject = subject;
message.IsBodyHtml = true;
if (cc != null) message.CC.Add(new MailAddress(cc));
SmtpClient smtpClient = new SmtpClient();
smtpClient.UseDefaultCredentials = false;
**smtpClient.Host = smtpClient.Host;// System.Configuration.ConfigurationManager.AppSettings["SMTPHost"];
smtpClient.Port = smtpClient.Port;// Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SMTPPort"]);**
smtpClient.Send(message);
}
以下是我发送邮件的方式:
Email message= new Email();
message.To=("me@atmytestdomain.com");
message.Subject = "test";
message.From = ("NoReply@atmytestdomain.com");
message.Body = "New line is now omitted"+System.Environment.NewLine;
message.Body += "New line is now omitted"+System.Environment.NewLine;
message.Body += "New line is now omitted"+System.Environment.NewLine;
message.Send();
提前致谢