Linux Email from Command Line with Attachment

Sep 28th, 2011

Today I was looking for sending attachment from command line. I use bash shell prompt and I wanted to use that so that I do not need to configure email client on my Linux (RedHat) system. I have found very good command line tool to send emails with or without attachment. It works like a charm. The client name is "mutt".

It works like the way you think. This is what I have like most. You just need to remember very few things to start using mutt. Try $mutt -v to check if it is installed. Most likely it will be there.

Try mutt yourself:
$mutt -s "vimrc Backup" -a ~/.vimrc satyaxxxxx@gmail.com
Above, -s is used for mail subject.
-a is used for attachment.
If you do not need to send attachment, then remove -a and its value after that.
Press Enter and it will start confirming for Subject: and To: part by showing it. Just press Enter or change the value if you need to.
After that it will open vi editor for email body. Type your email body and quit from editor. You will see mutt client application. Press y to send email.
Before sending, you can easily change anything you have already entered. Just look at the menu given at the top.

For sending blank email with Subject only:

$mutt -s "Test mail" -a /tmp/file.tar.gz satyaxxxxx@gmail.com

Instead of /dev/null, put your fileName with content for putting file content in your email body part.

Though, simple mail command is also good and can be used like the above. Method is almost same.

$mail -s "testing mail cmd" satyaxxxx@gmail.com
Press Enter and cursor will go to next line. Type your text for email body part and press Ctrl + d at new line. Next, it will ask for cc: value. Press Enter for no value and your mail is in queue to send.

 
Possibly Related posts:
  1. September 28th, 2011 at 20:11 | #1

    Very Useful Information even i also use Linux but never tried to send Email from it. but now i will surely do this..

  1. No trackbacks yet.

All comments will be moderated.

Mobify empowers marketers and developers to create amazing mobile web experiences. Tap to learn more

Mobify