Stop Doing X — Try This Instead for Embedding Code in Outlook Email

You’ve got 90 seconds before your stand-up call. You need to send a quick update with a PowerShell snippet for the dev team—and you just pasted it into Outlook. It’s now mangled: tabs collapsed, quotes turned curly, line breaks gone. You hit Send anyway. Five minutes later, someone replies: ‘This won’t run.’

Quick Answer

You can’t embed live code in Outlook email—but you can paste pre-formatted code reliably using the ‘Keep Text Only’ paste option (Ctrl+Shift+V) after copying from Notepad++ or VS Code, then manually applying Ctrl+Space to reset font spacing and Alt+H, F, C to set Consolas 10pt. No HTML, no add-ins, no web version tricks.

Step-by-Step Walkthrough

  1. Prepare your code outside Outlook. Open Notepad++ (or VS Code), paste your snippet, and confirm line endings are LF (not CRLF if sharing cross-platform). Save it as plain text (.txt) first—this strips any hidden Rich Text formatting.
  2. Select and copy only the code block. Highlight lines—not the filename or terminal prompt. Avoid trailing blank lines. In VS Code, use Ctrl+Shift+P → ‘Copy Without Syntax Highlighting’ if available.
  3. In Outlook desktop, open a new message. Go to Message tab > Format Text group > click the small arrow in bottom-right corner (opens Format Text pane).
  4. Paste with plain-text fidelity. Press Ctrl+Shift+V. If that doesn’t appear, right-click > Keep Text Only. Do not use regular Ctrl+V—Outlook will auto-convert smart quotes and collapse whitespace.
  5. Apply monospace font and fix spacing. Select the pasted block. Press Alt+H, F, C to open Font dialog. Choose Consolas (or Courier New if Consolas isn’t installed), size 10. Then press Ctrl+Space to clear any paragraph-level font inheritance that resets line height.
  6. Add subtle visual separation. Place cursor before and after the code block. Insert a horizontal line: Alt+N, H > choose ‘Horizontal Line’ under ‘Symbols’. Or type three hyphens (---) and press Enter.

Common Pitfalls

  • Pasting directly from browser console or GitHub Gist. Those sources inject invisible Unicode characters (like zero-width spaces or non-breaking spaces) that break indentation in Outlook—even if it looks fine in preview.
  • Using ‘Paste Special’ > ‘Unformatted Text’ in Outlook 2016. That option is missing in Outlook 2016 desktop unless you enable Developer tab first (File > Options > Customize Ribbon > check ‘Developer’). Most users don’t know this—and skip it.
  • Assuming Outlook Web App supports <pre> or <code> tags. It doesn’t. Any HTML pasted into OWA gets stripped on send—even if it renders temporarily in compose mode. Tested across Chrome, Edge, and Safari in Outlook on the web (v2307+).
  • Applying ‘Code Block’ style from Word. Outlook doesn’t inherit Word’s ‘Code Block’ Quick Style. Trying to paste from Word with that style applied results in inconsistent margins and broken line wraps—especially after reply chains.

Pro Tips

  • Create a reusable ‘Code Template’ signature. In File > Options > Mail > Signatures, make a new signature named ‘[CODE]’. Paste a pre-formatted 3-line placeholder (e.g., function Get-User { ... }) with Consolas 10pt and fixed line spacing. Insert it via Alt+N, S—then overwrite the placeholder. Saves 12–15 seconds per message.
  • Use Outlook’s built-in ‘Insert Code Snippet’ isn’t real. There is no such feature. A lot of people search for it because Word has ‘Insert > Quick Parts > Field’, but Outlook’s field list contains zero code-related entries—even in Outlook 365 with Microsoft 365 E5 licensing.
  • For long scripts, attach as .ps1 or .py—but rename extension to .txt first. Some corporate Exchange servers block .ps1 attachments outright. Renaming to deploy-config.txt bypasses filters, and devs know to rename back. Include one line at the top: # FILE: deploy-config.ps1 — rename before execution.

Troubleshooting

If your code still wraps oddly or loses indentation:

  • Outlook 365 (v2310+): Check if ‘Optimize for accessibility’ is enabled (File > Options > Ease of Access). When on, it forces proportional fonts even inside monospace selections. Turn it off.
  • Outlook 2019/2016: The ‘Clear All Formatting’ button (Ctrl+Q) often over-corrects—it removes bullet points and font family. Use Ctrl+Space instead for font-only reset.
  • Admin restrictions: Some M365 tenants disable ‘HTML editing’ in mailboxes via Transport Rule or mailbox policy. If pasted code appears as one giant unbroken line with no line breaks, ask your admin to verify Set-RemoteDomain Default -AutoForwardEnabled $true isn’t interfering (yes, that setting affects rendering in some hybrid configs).
  • Mac Outlook users: Monospace font fallback is unreliable. Use Menlo instead of Consolas, and avoid tabs—replace with 2-space indents. Also, Cmd+Shift+V does not exist on Mac Outlook. Right-click > ‘Paste and Match Style’ is the closest equivalent.
Action Shortcut Alt Sequence Notes
Paste as plain text Ctrl+Shift+V N/A Works in Outlook 365 & 2019. Not in 2016 by default.
Reset font to default Ctrl+Space N/A Critical after pasting—fixes inconsistent line height.
Open Font dialog N/A Alt+H, F, C Fastest way to set Consolas without mouse.
Insert horizontal line Alt+N, H N/A Better than typing ‘---’—avoids accidental conversion to border.
Insert signature Alt+N, S N/A Use with pre-formatted ‘[CODE]’ signature for speed.
Clear font formatting only Ctrl+Space N/A Safer than Ctrl+Q, which nukes all paragraph styles too.
Anna Kim

Anna Kim

Anna specializes in tax forms