How should I use Outlook to send code snippets?

Mag Roader picture Mag Roader · Jul 20, 2009 · Viewed 174.4k times · Source

As a programmer at a big corporation, I frequently send Outlook emails that contain code samples.

I'll actually type code directly into an email. This inevitably causes problems, as Outlook really likes to format text in pleasing but unhelpful ways. My code needs to be copyable out of the email and directly into code, so I don't want Outlook to mess with it by adding special characters or whatnot.

So I always need to tweak options like:

  • Don't capitalize first letter of every sentence (else all my functions be Public instead of public)
  • Disable smart quotes (fancy quotes don't copy+paste out of emails well)
  • Never use spell checker (because it just gets annoying)

I also like my code to be in a monospaced font, black, indented, and smaller than other text. I've tried to make a Style for this, but for some reason the Style never saves. :-( [edit: turns out I wasn't telling it to work on "new documents based on this template"]

Is there some way to put code in <pre> blocks or something that tells Outlook to ignore all these rules and format code the way I want it to? If not, what ways have you found to send code snippets in Outlook emails without it getting super annoying?

Answer

trueshot picture trueshot · Sep 8, 2012

Years later I have a response.

  1. Use an online code highlighter like http://tohtml.com/ to highlight your code so you can paste marked up code from your IDE into Word. Depending on your IDE you may be able to skip this step.

  2. In Word 2010, go to insert->object->openDocument Text. Steps 2-3 are documented at How do you display code snippets in MS Word preserving format and syntax highlighting?.

  3. Paste your highlighted code into the object.

  4. Copy the whole object.

  5. Right-click-> paste special the object into Outlook.

This gives you a highlighted, contained box of code for use in emails in Outlook 2010.