You can install the Markdown Here extension for Chrome and write the code in markdown format in the email compose window.
You can either write the code with a four-space indent:
Or with the triple backtick format:
Then, to turn the markdown code into a properly formatted email, activate the extension by right-clicking and selecting Markdown Toggle from the menu, clicking the extension button next to the address bar, or using the hotkey Ctrl Alt M.
Before and after screenshot: