Send Email from the Command Line using Gmail Account
Sometimes you want to send a quick/short E-mail to somebody, send a TODO item to yourself, or let a script/program Email you when it’s done. For these I found the Linux mail command very useful.
Using it is as easy as typing:
mail -s “Subject” receipt@domain.com
Then enter the message and end it with [ctrl]+[D].
However, if your ISP s!#$% like mine, you’ll discover that no mail was really sent.
To work around this, I wanted to configure my mail program to use Gmail’s SMTP server.
After a little Googling I found this howto. (Tested on Ubuntu).
1. First, you will need the postfix package:
sudo apt-get install postfix
2. Now configure it: Append the following to /etc/postfix/main.cf (you need super user privileges):
relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
3. Next, add your username and password to /etc/postfix/sasl_passwd (create the file if it isn’t already)
[smtp.gmail.com]:587 user.name@gmail.com:password
4. Change permissions of sasl_passwd:
sudo chmod 400 /etc/postfix/sasl_passwd
5. Translate sasl_passwd into “db” file so postfix will be able to read:
sudo postmap /etc/postfix/sasl_passwd
6. Create a certificate:
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | sudo tee -a /etc/postfix/cacert.pem
7. Restart postfix:
sudo postfix stop
sudo postfix start
8. Try it:
mail -s “Test” my.email@domain.com
(Then enter the message if any, and terminate with [ctrl]+[D])
That’s it. You’re done.
No related posts.
4 Comments to Send Email from the Command Line using Gmail Account
Leave a Reply
About Me
Tags
Categories
- Algorithms
- Bash
- BlackBerry
- Collaboration
- Command Line
- Cool Tricks
- Easter Eggs
- Ebooks
- Firefox
- Hardware
- Humor
- iPhone
- Linux
- Linux Development
- Linux Kernel
- Networks
- Open Knowledge
- Other
- Productivity
- Programming
- Regular Expressions
- Science
- Security
- Shell Scripts
- Short Posts
- Social Networks
- Thoughts
- Tools
- Vim
- Web Development
- Websites
Popular Posts
Calendar
Archives
- September 2010 (2)
- August 2010 (2)
- July 2010 (5)
- June 2010 (1)
- May 2010 (1)
- April 2010 (3)
- March 2010 (1)
- January 2010 (1)
- December 2009 (2)
- September 2009 (13)
- July 2009 (1)
- June 2009 (6)
- May 2009 (4)
- March 2009 (18)
- February 2009 (10)
- January 2009 (10)
- December 2008 (7)
- November 2008 (8)
- October 2008 (1)
- August 2008 (1)
- July 2008 (1)
- June 2008 (1)

hey…slam…mr7ba
ana…nareman bt3lam b el 7ashmal btw2a3 enak bt3rfne b el mnzar konet ma5de m3ak course mvne m7ashvem w esa sadot bde as2lak akam sha3′le b el mvne m7ashvem drore
so b7yatk eza momken teb3atle el mail tb3ak aw nomret tlfonak
Without postfix:
http://www.logix.cz/michal/devel/smtp-cli/
Thanks for this; most straightforward instructions I’ve found.
Down with Israel