send emails from terminal
28 Nov 2010
In some systems the command mail is installed by default and as its name suggests it’s used to send/read emails (usually between users of the same system), for this to work a mail server needs to be installed locally, I’m not sure about others but it sounds like a lot of work for me. I just want a light client from where I could send some emails. After searching on Internet I came to Sendemail, a perl script who connects to external smtp servers and use them to deliver messages:
$ sendemail -f email@example.com \ -u title -m message \ -t firstname.lastname@example.org \ -s mail.foo.com:26 \ -xu user -xp password
It requires the following libraries to work with gmail, libio-socket-ssl-perl, libnet-ssleay-perl:
$ sendemail -f email@example.com \ -u title -m message \ -t firstname.lastname@example.org \ -s smtp.gmail.com:2587 \ -o tls=yes -xu user -xp password
Now, since gmail blocks hosts per ip, it sometimes doesn’t work when it used from new locations, it can be very annoying. Fortunately, there are other ways to send emails within a system, my favorite method is to use http://mailgun.com. When using mailgun you only need an account in such service and curl installed in your system. I’ve created a script who wraps the required logic and just send emails.
$ wget https://raw.github.com/chilicuil/learn/master/sh/tools/mailgun $ sh mailgun --api xxx "email@example.com" "message"