我正在尝试通过在创建时传入一个字符串来在电子邮件正文中创建 2 个项目列表。其中一个列表可以完美运行,没有任何问题(IE 每个条目都在一个新行上,正如预期的那样),但我无法弄清楚如何以相同的方式格式化另一个列表。要么没有新行,要么双行距。我已经尝试过 System.environment.newline、“\r\n”、“\n”、“\n”等。当我在代码中设置断点时,字符串在适当的位置有 '\n'地点,但在创建电子邮件时未显示。有小费吗?
string users = "";
for (int i = 0; i < disabledUsers.Count; i++)
{
users += disabledUsers[i] + "\n"; //This does not show up as a new line for each item in an email
}
// initializing users with expired passwords to a string format
string expiredUserPasswords = "";
for (int i = 0; i < expiredPassword.Count; i++)
{
expiredUserPasswords += expiredPassword[i] + "\n"; //this works perfectly
}
// creating admin message
MailMessage emailAdmin = new MailMessage();
emailAdmin.From = new MailAddress("email.email@email.com");
emailAdmin.Body = "Automated system message:\n\nThe following " + numExpiredPasswords + " accounts have expired passwords and have been disabled:\n\n" + expiredUserPasswords + "\n\nThe following " + numDisabledAccounts + " accounts have been disabled for 90+ days:\n\n" + users + "\n\nThere are " + activeNum + " active users, " + numDisabled + " disabled users, and " + totalNum + " total users.\n\nThis is an automatically generated email. Please do not reply.";
emailAdmin.Subject = "Dataroom cleanup log";
我看不出这两个列表之间有什么区别,以及为什么一个工作正常而另一个不能工作。任何帮助,将不胜感激!
编辑 - 我想通了。感谢 Microbloft,Outlook 会自动删除它认为过多的换行命令。我通过在换行符之前添加一个句点来修复它,所以“。\ n”。