-1

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 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.

user441521
  • 6,942
  • 23
  • 88
  • 160
  • 1
    Let me guess: The font is non-proportional (e.g. Arial). Set your mail program to use a monospace font (e.g. Courier New) – Thomas Weller Feb 08 '18 at 17:58
  • Either use monospace as @ThomasWeller suggested, or use HTML to line things up. –  Feb 08 '18 at 18:02

1 Answers1

0

By default body uses us-ascii encoding

try using

email.BodyEncoding = System.Text.Encoding.UTF8;

MSDN Reference for BodyEncoding

NOTE: I haven't tested this is just speculation.