Ask HN: Free,reliable SMTP service for sending emails from cron jobs in Mac OS X

3 points by graffitici ↗ HN
Hi all,

I usually have several cron jobs running in the background that output their results to text files. I then have to remember to check these files regularly. I figured it would be more productive to just send these to my e-mail.

I use Mac OS X, and I found ways to set up Gmail so that I can use the command-line `mail` client (http://www.anujgakhar.com/2011/12/09/using-macosx-lion-command-line-mail-with-gmail-as-smtp/). But all of these require me writing my Google password in cleartext (?!).

Do you know of a free service that I can set up for this purpose? Since I would only use it for piping the output of these cron jobs, I wouldn't mind writing the pass in cleartext.

I figured I could open up a Gmail account just for this purpose, but that somehow feels like a bit of a hack..

8 comments

[ 4.8 ms ] story [ 28.9 ms ] thread
Both sendgrid.com and mailgun.com offer 10.000 emails/month for free. I use them inside cronjob scripts on cloud hosters where the standard sendmail/exim setup was too complicated or where the IP is blocked by various anti-spam lists.
Mandrill is a very good SMTP service. It's by the same people who do MailChimp

You can use traditional SMTP commands or use their API and it's free for up to 12,000 emails per month

https://mandrill.com/

I use mandrill as well and it's been really good. Easy to setup, reliable, good features to monitor things, etc... And free for up to 12000 emails/month. Pretty reasonable after that.

Otherwise you could just send through a gmail account as well if it's not going to be that many of them.

Cron already supports sending email for jobs (or at least the cron's on Unix/Linux machines do so). Just don't redirect the output anywhere and cron emails it to the owner of the cron job. Assuming that MacOS's cron is not too far modified, all you need is a replacement "sendmail" command, in the location that MacOS cron would look for it, that submits cron's output to an SMTP server for delivery.

Given that MacOS already ships with Tcl/Tk, if you install TclLib (http://wiki.tcl.tk/1246) such that the native Tcl/Tk can find it (note, I have no Mac, so I have no knowledge of 'how' to install TclLib on MacOS) then you need a four line Tcl script to create a replacement "sendmail" command:

    #!/usr/bin/tclsh

    package require mime
    package require smtp

    set mesg [::mime::initialize -string [read stdin]]

    ::smtp::sendmessage $mesg -servers smtp.server.name.com \
        -client this.machines.name.com \
        -originator email@address.to.use.as.from.com \
        -recipients destination@email.address.com
Replace 'smtp.server.name.com', 'this.machines.name.com', 'email@address.to.use.as.from.com', and 'destination@email.address.com' with the appropriate items for your environment and you (on Linux, at least) will be good to go. Hopefully MacOS's cron is not too far afield from standard Unix cron.
Thanks for the answer. I'll look into Mac OS X cron's ability to send output.

But my main answer was in finding an SMTP service that can send emails. In your example, don't you have to log in to smtp.server.name? If so, don't you need to put a password somewhere in that tcl script?

Yes, but as I own my domain name and run my own email, the smtp server I use is mine. You could try looking up google's SMTP server and try it to see if it would work (it should):

    nslookup -q=mx google.com
    ...
    google.com      mail exchanger = 10 aspmx.l.google.com.
    google.com      mail exchanger = 20 alt1.aspmx.l.google.com.
    google.com      mail exchanger = 30 alt2.aspmx.l.google.com.
    google.com      mail exchanger = 40 alt3.aspmx.l.google.com.
    google.com      mail exchanger = 50 alt4.aspmx.l.google.com.
I also found Nilas: https://www.nilas.com/

It's not an SMTP server, but translates between REST calls and SMTP/IMAP commands (as far as I understand). So they store my Google credentials on their server, I keep an API key in cleartext, and use their infrastructure to both send and look at e-mails..

Anybody has experience with this?

AIUI, you're basically asking for a (free) open relay. There are very good reasons why those are pretty much non-existent nowadays. Good luck.