On Windows:
You could use Notepad++ to achieve the desired effect.
- Open the source file in Notepad++.
- Highlight the text you want to copy.
- Right click and select Plugin commands > Copy Text with Syntax Highlighting
- Paste the text into Gmail.
On OS X:
TextMate has a copy-as-RTF that people are raving about. They use it to paste code with syntax highlighting on KeyNote.
From their GitHub page:
Need to copy + paste some text and keep the syntax highlighting? Yes you do. All the time. For Keynote presentations. And probably other reasons. Install this bundle, and after selecting some pretty syntax highlighted text, use Ctrl+Alt+Cmd+R to copy it as RTF (rich text format) Now you can paste it directly into Keynote presentations. And other places where RTF is supported. Should work on Gmail's composer too.