Results 1 to 3 of 3

Thread: C# Can I send a "formatted" SMTP email without using HTML?

  1. #1

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    C# Can I send a "formatted" SMTP email without using HTML?

    I am pretty sure the answer is no.

    Can I send an email that is formatted as columns without using HTML?

    So for example I want Employee Name,Date of Task and Task Type as the header with serveral rows of data to follow.
    Obviously Employee Name can be variable length. Our shortest employee name is 8 and the longest is 18. I would want them to all line up in the first column.
    The second column, date, you'd think would be trivial but when I convert my date, which is a cell in a grid like so - Convert.ToDateTime(gvTasks.GetRowCellValue(i, "ScheduledTime")).ToShortDateString(), I don't get dd if the day is the 1st - 9th of the month. Meaning it's , 10/1/22 not 10/01/22. That is easily addressed but 10/01/22 is not the same length as 10/11/22 because a 1 is skinnier than a 0 so there's still a problem because I don't have control over the font.

    The reason I can't use HTML is my code doesn't actually send email. It creates database rows that our mail service processes and the author of that code is not caring about formatting. I have to somehow put "MsgText" into the database with formatting embedded even though it will be Basic Text in Outlook.

    So given these limitations I tried using tabs (\t), I tried using PadRight(), I started looking into SetTabStops() ... but maybe the answer is just no. Which would be fine. The receiver of the email is more concerned with its content than if it's pretty, but of course as developers we like to make things perfect :-).

    Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,929

    Re: C# Can I send a "formatted" SMTP email without using HTML?

    Unfortunately there isn't much you can really do, because each mail client will deal with displaying things differently (eg: different widths for tab), and each font will also display text in different widths (for some W is really wide, and in other cases it's quite thin).

    Even if you have a known client (eg: Notepad) and font (other than fixed-width fonts), you still can't make things work properly... you can get them a bit better, but there are still lines that are wrong (because the width of text goes just past a tab limit).


    The best you can probably do is use spaces after the text (based on experience of this kind of thing I'd use 2 per 'missing' character) followed by a tab or two.

  3. #3

    Thread Starter
    PowerPoster MMock's Avatar
    Join Date
    Apr 2007
    Location
    Driving a 2018 Mustang GT down Route 8
    Posts
    4,475

    Re: C# Can I send a "formatted" SMTP email without using HTML?

    @si_the_geek - Yes, that was also my understanding. Just wanted to make sure I wasn't missing anything. Thanks.
    There are 10 kinds of people in this world. Those who understand binary, and those who don't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width