As mutt is text based, it can often prove difficult to open up an attachment, a PDF for example. However, you can tell mutt to pass the attachment on to another application to resolve. In this way, you can pretty much do whatever you need remotely on the CLI. Other times you may need to inform mutt of what mime type an attachment is. Here's how...
Opening different mime type attachments
All attachments have a mime type which specifies what they are. At runtime mutt will read in ~/.mailcap if it exists. This is the file you can use to specify which applications are to be used to resolve specific mime types. So here's a simple example:
text/html; cat %s | w3m -T text/html application/pdf; pdftotext -layout %s - | less
As you can see, the text/html mime type is resolved by cating the file to the w3m text browser. For a PDF document, we pass it through pdftotext and then less it.
It may be important to note that mutt will wait for the application to exit before resuming normal operation.
You will also be pleased to know that there is no restriction to CLI based apps only - you can use GUI apps if you like running mutt in gnome or something similar.
Adding different mime type attachments
It is possible that mutt will not know what mime type to use with a file you wish to attach to an email; just look at what we've been doing so we can correctly open a file based on mime type. However, it is possible to give mutt a helping hand.
Mutt supports the use of a ~/.mime.types file where additional mime types can be specified. A simple example:
application/postscript ps eps application/pgp pgp audio/x-aiff aif aifc aiff
As you can see the file consists of lines containing a MIME type and a space separated list of extensions.
I access my email via the CLI. I don't need HTML and the like to make an email look pretty for me, I simply want to get to the email, read it, reply if necessary and carry on with my life. As such, I use mutt for all my email needs. So much so, that I use it to get my gmail emails too...
With some help from andre, I was able to set up two email accounts in mutt so that each email is sent via its own SMTP server - configured via a account-hook. Swicthing between them is a case of pressing <esc><1> or <esc><2> - allowing for more accounts to be assigned to other numbers.
Here's the example with one account for the domain example.com and another for gmail.com:
# clear any existing accounts account-hook . 'unset imap_user; unset imap_pass; unset tunnel' # home account setup account-hook imap://email@example.com/ 'set imap_user=username imap_pass="XXX"' folder-hook imap://firstname.lastname@example.org/ 'set folder=imap://email@example.com/ spoolfile=imap://firstname.lastname@example.org/INBOX from="username <email@example.com>" smtp_url="smtp://127.0.0.1/" record="=Sent"' # gmail account setup account-hook imaps://imap.gmail.com:993/ 'set imap_user=gmailuser imap_pass=XXX' folder-hook imaps://imap.gmail.com:993/ 'set folder=imaps://imap.gmail.com:993/ spoolfile=imaps://imap.gmail.com:993/INBOX from="gmailuser <firstname.lastname@example.org>" smtp_url="smtp://email@example.com:587/" smtp_pass="XXX" record="=[Gmail]/Sent Mail"' # set default account on startup set folder=imap://firstname.lastname@example.org/ set spoolfile=imap://email@example.com/INBOX # set mutt style and colors source ~/mutterings/style # macros to change profile macro index <esc>1 'c?c<kill-line>imap://firstname.lastname@example.org/<enter>/INBOX<enter><enter>' macro index <esc>2 'c?c<kill-line>imaps://imap.gmail.com:993/<enter>/INBOX<enter><enter>'
I have my stylesheet in a seperate file to keep ~/.muttrc detailing only account configurations, but this is a personal choice.