换行符在电子邮件中不起作用 - .net Windows 服务
我们在发送电子邮件时遇到一个奇怪的问题。看来新线路并不总是有效。我们的代码是
string mailSubject = "EBN Import Success. Client: " + ClientName.Trim();
StringBuilder mailBody = new StringBuilder("Client Name: " + ClientName.Trim());
mailBody.Append(System.Environment.NewLine + "File Name: " + FileName);
mailBody.Append(System.Environment.NewLine + "FileID: " + FileId);
mailBody.Append(System.Environment.NewLine + "BatchID: " + BatchID);
mailBody.Append(System.Environment.NewLine + System.Environment.NewLine + "Records in File (or staging): " + noOfRecords.ToString());
mailBody.Append(System.Environment.NewLine + "Records imported into BNCStaging: " + noOfRecords.ToString());
mailBody.Append(System.Environment.NewLine + "Records imported into EBNTrackings: " + noOfRecords.ToString());
string mailTo = ConfigurationManager.AppSettings["ErrorEmailTo"].ToString();
string mailFrom = ConfigurationManager.AppSettings["EmailFrom"].ToString();
string mailHost = ConfigurationManager.AppSettings["EmailServer"].ToString();
SmtpClient mailClient = new SmtpClient(mailHost);
mailClient.Send(mailFrom, mailTo, mailSubject, mailBody);
我们得到的输出是
客户端名称:[客户端名称]文件名:[文件名]
文件 ID:nnnn
BatchID:mmmm
文件(或暂存)中的记录:x
导入 BNCStaging 的记录:y
导入 EBNTrackings 的记录:z
(即客户端名称和文件名)位于同一行。
我们还尝试过 AppendLine() 和 '\n' 但没有成功。
有什么建议吗...
顺便说一句,我们使用的是.net 4.0,邮件客户端是outlook
We are facing a strange issue while sending email. It seems that the new line is not always working. Our code is
string mailSubject = "EBN Import Success. Client: " + ClientName.Trim();
StringBuilder mailBody = new StringBuilder("Client Name: " + ClientName.Trim());
mailBody.Append(System.Environment.NewLine + "File Name: " + FileName);
mailBody.Append(System.Environment.NewLine + "FileID: " + FileId);
mailBody.Append(System.Environment.NewLine + "BatchID: " + BatchID);
mailBody.Append(System.Environment.NewLine + System.Environment.NewLine + "Records in File (or staging): " + noOfRecords.ToString());
mailBody.Append(System.Environment.NewLine + "Records imported into BNCStaging: " + noOfRecords.ToString());
mailBody.Append(System.Environment.NewLine + "Records imported into EBNTrackings: " + noOfRecords.ToString());
string mailTo = ConfigurationManager.AppSettings["ErrorEmailTo"].ToString();
string mailFrom = ConfigurationManager.AppSettings["EmailFrom"].ToString();
string mailHost = ConfigurationManager.AppSettings["EmailServer"].ToString();
SmtpClient mailClient = new SmtpClient(mailHost);
mailClient.Send(mailFrom, mailTo, mailSubject, mailBody);
The output we are getting is
Client Name: [Client Name]File Name: [File Name]
FileID: nnnn
BatchID: mmmm
Records in File (or staging): x
Records imported into BNCStaging: y
Records imported into EBNTrackings: z
that is the client name and file name are coming in the same line.
We have also tried with AppendLine() and with '\n' without luck.
Any suggestions...
By the way we are using .net 4.0 and the mail client is outlook
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Outlook 中,单击
此邮件中的额外换行符已删除
,然后单击恢复换行符
。In Outlook, click
Extra line breaks in this message were removed
, then clickRestore line breaks
.这可能听起来很荒谬,但请尝试在“客户名称”行中添加一个句点。据我处理过,这似乎迫使 Outlook 接受换行符,而不是“智能地”将句子包装在一起。
It might sound ridiculous, but try adding a period to the Client Name line. As far as I have worked with this, this seems to force outlook into accepting the newline, instead of "intelligently" wrapping sentences together.
您是否尝试在行尾显式发生
"\r\n"
?did you try to explicitly happend
"\r\n"
at the end of the line ?