How should I use Outlook to send code snippets?

OutlookOutlook 2007

Outlook Problem Overview


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?

Outlook Solutions


Solution 1 - Outlook

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 https://stackoverflow.com/questions/387453/best-way-to-show-code-snippets-in-word.

  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.

Solution 2 - Outlook

If you have notepad++ installed in your pc, then you can copy text as RTF (Rich Text Format) and paste it in your outlook mail.

  1. Paste you code snippet into notepad++

  2. From Menu bar navigate to "Plugins -> NppExport -> Copy RTF to clipboard"

  3. Paste into your email

  4. Done

Solution 3 - Outlook

If you are using Outlook 2010, you can define your own style and select your formatting you want, in the Format options there is one option for Language, here you can specify the language and specify whether you want spell checker to ignore the text with this style.

With this style you can now paste the code as text and select your new style. Outlook will not correct the text and will not perform the spell check on it.

Below is the summary of the style I have defined for emailing the code snippets.

Do not check spelling or grammar, Border:
Box: (Single solid line, Orange,  0.5 pt Line width)
Pattern: Clear (Custom Color(RGB(253,253,217))), Style: Linked, Automatically update, Quick Style
Based on: HTML Preformatted

Solution 4 - Outlook

I came across this looking for a way to format things better in an email to a co-worker. I ended up discovering that if you copy from Visual Studio Code (FREE) it retains the formatting, highlighting and everything else. This editor works with everything and has modules for every programming language I've ever encountered.

Looks beautiful in the email.

Solution 5 - Outlook

Here's what works for me, and is quickest and causes the least amount of pain / annoyance:

  1. Paste you code snippet into sublime; make sure your syntax is looking good.

  2. Right click and choose 'Copy as RTF'

  3. Paste into your email

  4. Done

Solution 6 - Outlook

If you attach your code as a text file and your recipient(s) have "show attachments inline" option set (I believe it's set by default), Outlook should not mangle your code but it will be copy/paste-able directly from email.

Solution 7 - Outlook

When I paste code into Outlook or have sentences containing code or technical syntax I get annoyed by all of the red squiggles that identify spelling errors. If you want Outlook to clear all of the red spellcheck squiggles you can add a button to the Quick Access Toolbar that calls a [VBA macro](https://stackoverflow.com/a/49865743/1898524 "Outlook VBA macro to Ignore Spelling Errors in Text") and removes all squiggles from the current document.

I prefer to run this macro separate from my style choice because I often use it on a selection of text that has mixed content.

For syntax highlighting I use the Notepad++ technique already listed by @srujanreddy, though I discovered that the right-click context menu option a bit handier than navigating the Plugins menu.

Image showing you can right-click on selected text and choose to copy text with syntax highlighting

If you get annoyed by spell check while you are preparing your email you can add a button to your quick access toolbar that will remove the red squiggles from the message body.
See this article: https://stackoverflow.com/a/49865743/1898524

Remove Spell Check Squiggles

[tag:outlook-vba]

Solution 8 - Outlook

For me VS Code works best.

  1. Copy the code snippet in VS Code empty file
  2. Save the file with required extension .cpp,.js etc
  3. Copy the code snippet to clipboard
  4. Paste into outlook.

Solution 9 - Outlook

If you do not want to attach code in a file (this was a good tip, ChssPly76, I need to check it out), you can try changing the default message format messages to rich text (Tools - Options - Mail Format - Message format) instead of HTML. I learned that Outlook's HTML formatting screws code layout (btw, Outlook uses MS Word's HTML rendering engine which sucks big time), but rich text works fine. So if I copy code from Visual Studio and paste it in Outlook message, when using rich text, it looks pretty good, but when in HTML mode, it's a disaster. To disable smart quotes, auto-correction, and other artifacts, set up the appropriate option via Tools - Options - Spelling - Spelling and AutoCorrection; you may also want to play with copy-paste settings (Tools - Options - Mail Format - Editor Options - Cut, copy, and paste).

Solution 10 - Outlook

Would sending the mail as plain-text sort this?

"How to Send a Plain Text Message in Outlook":

> - Select Actions | New Mail Message Using | Plain Text from the menu in Outlook. > - Create your message as usual. > - Click Send to deliver it.

Being plain text it shouldn't screw up your code, with "smart" quotes, auto-capitalisation and such.

Another possible option, if this is a common problem within the company perhaps you could setup an internal code-paste site, there's plenty of open-source ones around, like Open Pastebin

Solution 11 - Outlook

Well this is late answer, but if you don't absolutely need it to be in text format, then why just simply copy/paste a screenshot taken with some tool like Windows build-in Snipping tool ?

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMag RoaderView Question on Stackoverflow
Solution 1 - OutlooktrueshotView Answer on Stackoverflow
Solution 2 - Outlooksrujan reddyView Answer on Stackoverflow
Solution 3 - OutlookmehulView Answer on Stackoverflow
Solution 4 - OutlookAllen GeorgeView Answer on Stackoverflow
Solution 5 - Outlooktumultous_roosterView Answer on Stackoverflow
Solution 6 - OutlookChssPly76View Answer on Stackoverflow
Solution 7 - OutlookBenView Answer on Stackoverflow
Solution 8 - OutlookenigmaView Answer on Stackoverflow
Solution 9 - OutlookAlek DavisView Answer on Stackoverflow
Solution 10 - OutlookdbrView Answer on Stackoverflow
Solution 11 - OutlookvpalmuView Answer on Stackoverflow