How to Send a Block of Code in Outlook

As more organizations adopt tools like Microsoft Teams, it’s evident how crucial collaboration is to a project’s success. In software development, this idea is reinforced by the popularity of Agile methodologies that focus on teamwork and communication.

Outlook, perhaps the most basic form of collaboration, is sometimes the most readily available tool. Developers looking to send a quick code sample to a colleague might find that doing so is harder than they originally imagined.

Sending a block of code in Microsoft Teams is easy, but there’s no built-in functionality for it in Outlook. Luckily, there’s a few ways you can work around this – here’s how.

Format Code Blocks in Outlook with a Custom Style

You can use custom styles in Outlook to create something similar to a block of code. It will keep your original formatting, and not auto-correct spelling errors, but it won’t show syntax highlighting.

  1. Open Outlook and start a new email.
  2. Under the Format Text tab, click the Show More button at the bottom right of the pre-defined styles and select Create a Style.
    Outlook More Styles Button
    Outlook Create Style in More Styles Menu
  3. Click the Modify button so that all available options are shown.
    Outlook Modify Button in Create New Style Window
  4. Optionally name the style, then set the Style based on field to HTML Preformatted.
    Outlook Style Name and Style Based On Fields in Create New Style Window
  5. Check the Automatically update box and click New documents based on this template (This saves the style for future use).
    Outlook Automatically Update Checkbox and New Documents Based on This Template Radio Button in Create New Style Window
  6. Click the Format button at the lower left corner and select Border...
  7. Select the Shading tab and change Fill to a light gold or yellow.
    Outlook Fill Color in Borders and Shading on Custom Style
  8. Select the Borders tab and change the Setting to Box and the Color dropdown to orange.
    Outlook Border Setting and Color in Borders and Shading on Custom Style
  9. Click the OK button.
  10. Back in the Create New Style window, click the Format button again and select Language...
  11. Select your preferred language and check the Do not check spelling or grammar checkbox.
    Outlook Do Not Check Spelling Checkbox in Language on Custom Style
  12. Click OK.
  13. Back in the Create New Style window, the preview should look like the below. Click OK if so.
    Outlook Code Block Custom Style Preview
  14. Paste or type your code into the new custom style you’ve created! Here’s what it should look it:
    Outlook Code Block Custom Style in Email

You can also re-use this style by selecting it in the custom styles gallery under the Format Text tab.

Copy and Paste a Block / Snippet of Code from Notepad++ and Other Text Editors

Notepad++, Sublime, and other text editors allow you to copy text in Rich Text Format (RTF) or HTML. You can then paste this block of code into Outlook and keep both the formatting and syntax highlighting.

Any IDE or text editor that supports this will work. We’ll show you how it’s done in Notepad++ below.

  1. Open Notepad++ and paste or type your code.
  2. Click the Language tab and select the language your code is in. This is for syntax highlighting.
    C plus plus in Language Selector in Notepad plus plus
  3. Select all text (Ctrl +A), then click the Plugins tab, hover over NppExport, and select Copy RTF to cliboard or Copy HTML to clipboard.
    Copy to RTF and HTML in Notepad plus plus
  4. Paste the contents of your clipboard in an Outlook email.
    Block of Code in Outlook with Formatting and Syntax Highlighting

Copy and Paste Preformatted Code Using a Third Party Web Service

There are some third party websites that provide code formatting and syntax highlighting online. Both Outlook and Microsoft Word will keep this formatting when you copy it from the site and paste it into either of these applications.

Here’s how to use one such service, ToHTML, to send a block or snippet of code in Outlook.

  1. Open tohtml.com in any web browser.
  2. Paste your code into the Source code box and click Highlight. It should auto-detect the language but you can use the box to the right of Source code to manually choose a language.
    ToHTML WebApp Highlight Button with Source Code
  3. Copy the code from the generated preview and paste it into Outlook!
    ToHTML WebApp Source Code Preview
    Block of Code in Outlook with Syntax Highlighting by ToHTML Website

1 thought on “How to Send a Block of Code in Outlook”

Leave a Comment