jump to navigation

How to send email from the command line – Gmail Mutt – November 10, 2010

Posted by Tournas Dimitrios in Linux.

If you are like me, you really like the command line. And sending email while working on the command line, is good, I use it to send me notes to myself, and sometimes to send configuration files as attachments. Is also good to have an option configured to send emails from the command line, as a way to send messages from scripts. I will show you now how to use mutt and gmail to enable a Linux computer to send email. First thinks first …… #rpm -q mutt  . If mutt is not yet installed on your Centos distro do #yum install mutt . The next step is to configure mutt with our gmail acount details , so create a file .muttrc (dot muttrc) and put inside the file the folowing contents .

set from = "user@gmail.com"
set realname = "Tournas Dimitrios"
set imap_user = "your_gmail_address@gmail.com"
set imap_pass = "your_gmail_password"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed ="+[Gmail]/Drafts"
set header_cache =~/.mutt/cache/headers
set message_cachedir =~/.mutt/cache/bodies
set certificate_file =~/.mutt/certificates
set smtp_url = "smtp://user@smtp.gmail.com:587/"
set smtp_pass = "your_gmail_password"
set move = no 
set imap_keepalive = 900

  • mkdir -p /.mutt/cache
  • mutt -s “Test from mutt” address_to_send@yahoo.com < /tmp/message.txt (just a message)
  • <mutt -s "Test from mutt" user@yahoo.com < /tmp/message.txt -a /tmp/file.jpg (include an attachment)

-s “Test from mutt” is the subject
-a /tmp/file.jpg is the attachment
/tmp/message.txt is the message itself

This is another way to write the test, having the body in the same line.
echo “This is the body” | mutt -s “Testing mutt” user@yahoo.com -a /tmp/XDefd.png

If you need to use send emails from a script, just use that line in the script, but be sure that is the user that has the .muttrc file in his / her home directory the one that runs the script.



No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s