Send Mail with Attachment Using Mutt in GNU/Linux

I have tried a couple of programs to send mail in my GNU/Linux system, and I’ll be honest, the majority of them are clunky to use, not until I tried Mutt.

Mutt is a powerful text-based mail client for Unix or GNU/Linux operating systems. It features:

  • color support
  • message threading
  • MIME support (including RFC2047 support for encoded headers)
  • various features to support mailing lists, including list-reply
  • POP3 support
  • IMAP support
  • full control of message headers when composing
  • highly customizable, including keybindings and macros
  • change configuration automatically based on recipients, current folder, etc.
  • searches using regular expressions, including an internal pattern matching language
  • easily include attachments when composing, even from the command line
  • ability to specify alternate addresses for recognition of mail forwarded from other accounts, with ability to set the From: headers on replies/etc. accordingly
  • multiple message tagging
  • reply to or forward multiple messages at once
  • small and efficient
  • It’s free! (no cost and GPL’ed)
  • and many more

Install mutt using:

To get started, simply enter ‘mutt’, if you don’t already have a mailbox in place it would show:

/home/user/Mail does not exist. Create it? ([yes]/no):

Click y if you want it to create a mailbox for your user, and you should see something as follows:

1. Mutt mailbox

To view your root mailbox, simply enter ‘sudo mutt’, and if a mailbox is available you’ll see something as follows:

2. Root mailbox

Sending Mail With mutt

There are a couple of ways you could send a mail with mutt, you can either use the text-based interface or use it directly in your shell, I’ll show you both ways:

To send mail via the interface, use the following steps:

  1. Type m in your keyboard, and beneath the interface you’ll see a “To:” enter the address you which to send email to
  2. Enter Subject, hit Enter and you’ll be taken to your editor, this is where you would compose the message. Compose your message and save
  3. To send the mail, simply type y

To send it via the command line, you do the following:

					

echo "" | mutt -s "subject" -i body.txt recipient@example.com

-s flag is used to specify the subject line of the email Also, -a flag is used to specify the location of the attachment file.

-i used to specify a file containing the message body.

Sending Mail With Attachment

There are a couple of ways you could send a mail with attachment using mutt, you can either use the text-based interface or use it directly in your shell, I’ll show you both ways:

To send mail via the interface, use the following steps:

  1. Type m in your keyboard, and beneath the interface you’ll see a “To:” enter the address you which to send email to
  2. Enter Subject, hit Enter and you’ll be taken to your editor, this is where you would compose the message. Compose your message and save
  3. Now, you’ll see ‘Attach file (‘?’ for list): enter ?, and attach file in that directory. You can also change the directory where the file is located by typing c, once you are done…
  4. Type y to send

To send a mail with attachment via the command line, you do the following:

					

mutt -s "subject" recipient@example.com -a attachment.txt

-a is used to used to specify attachment file. If you don’t place -a end of the option, it won’t work.

Comment policy: Respectful and beneficial comments are welcome with full open hands. However, all comments are manually moderated and those that doesn't relate with what the passage is saying or offensive comments would be deleted. Thanks for understanding!

Leave a Reply

Your email address will not be published. Required fields are marked *