Sometimes I need to send a fragment of code on google-group inline. Text does not help here; I can type it in markdown, convert it to html (using pandoc etc.), attach to mutt as text/html and send it.
There is one good solution available here but it uses external sendmail program to send email. I am using mutt which has capabilities to send emails over IMAP by itself.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
After you compose a message, but before sending you have lots of options available to you. Press ? to view them.
Some that may help here:
Fto filter the attachment through an external processor- Use
pandoc -s -f markdown -t htmlto convert to HTML
- Use
^Tto edit the attachment MIME type- Change from
text/plaintotext/html.
- Change from
Now a macro that will do everything in one step. Add this to your .muttrc:
macro compose e5 "F pandoc -s -f markdown -t html ny^T^Utext/html; charset=utf-8n" set wait_key=no
To use this macro, after you have finished composing your message but before you send, press Esc then 5 to convert your markdown formatted message into HTML.
You can naturally customize this macro as you see fit. Mutt has lots of key bindings already built in, so whatever key sequence you choose to bind to, make sure it doesn’t overwrite something else (or it’s something you can live without).
The option set wait_key=no suppresses Mutt’s Press any key to continue... prompt when external commands are run. If wait_key is yes (which is the default) you’ll have to press Esc, then 5, then any other key to continue.
Method 2
You can send e-mails also as a multipart/alternative containing both text/plain and text/html.
Requirements: pandoc
Basically it creates from markdown message plaintext and html5. Creates attachments from those parts, marks them as inline attachments, set correct mime type and combine them into mutlipart message.
Any other attachments are supposed to be added after running this macro in compose menu. Optionally signing/encrypting message should be done as the final step
macro compose ,m "<enter-command>set pipe_decode<enter> <pipe-message>pandoc -f gfm -t plain -o /tmp/msg.txt<enter> <pipe-message>pandoc -s -f gfm -t html5 -o /tmp/msg.html<enter> <enter-command>unset pipe_decode<enter>a^U/tmp/msg.txtn^Da^U/tmp/msg.htmln^D^T^Utext/html; charset=utf-8n=DTT&d^Un" "Convert markdown gfm to HTML and plain"
Method 3
Sendmail is often not flexible enogh for sending mails.
I use msmtp together with mutt on particular accounts for flexible SMTP.
To use it with mutt change:
# ~/.muttrc set sendmail="/usr/bin/msmtp -a default"
and
# ~/.msmtprc defaults tls off logfile ~/.msmtp.log account default host your.smtp.host port 25 from <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="dea7b1abacf3abadbbacf3b0bfb3bb9ea7b1abacf3b6b1adaaf0bdb1b3">[email protected]</a> auth off user username password password
Method 4
I can send email in any format using neomutt. I just use Emacs (org-mode), instead of vim. Although, I am a vim user as well. But, I mostly use Emacs with evil-mode.
In my .muttrc I have set up the editor to be emacs instead of vim. When writing a new email, neomutt fires emacs up. Then I call “org-mode”, write the message, and export to whatever format I want.
I can export to PDF format. Then I save it and attach the PDF file in my /tmp. After that I can send to whomever.
If I want the html format, I export that in the same way and I automatically can see the output, before sending the email.
Apart from that, there are many other export formats in org-mode. Just, choose what you want. For sending code to other people, just add the source code to whatever language you want. Everything is explained in the org-wiki.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0