[英]C# MailMessage string format
I'm trying to get strings to line up in an email.我正在尝试让字符串在电子邮件中排列。 Everything looks fine when I set the Body of the MailMessage but things aren't lined up when I get the email.当我设置 MailMessage 的正文时,一切看起来都很好,但是当我收到电子邮件时,事情并没有排列好。
MailMessage email = new MailMessage();
//...setup from/to/host/port etc
StringBuilder data = new StringBuilder();
data.AppendLine(string.Format("{0, -20} {1, -20}", "Id:", "26"));
data.AppendLine(string.Format("{0, -20} {1, -20}", "Name:", "Jeff"));
// this looks fine in console
Console.WriteLine(data.ToString());
email.Body = data.ToString();
// this looks fine in console
Console.WriteLine(email.Body);
When I get this email it's format is not lined up like email.Body text has it.当我收到这封电子邮件时,它的格式不像电子邮件那样排列。正文有它。
By default body uses us-ascii
encoding默认 body 使用us-ascii
编码
try using尝试使用
email.BodyEncoding = System.Text.Encoding.UTF8;
MSDN Reference for BodyEncoding BodyEncoding 的 MSDN 参考
NOTE: I haven't tested this is just speculation.注意:我没有测试过这只是猜测。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.