

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

Hi all,<p>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.<p>I use Mac OS X, and I found ways to set up Gmail so that I can use the command-line `mail` client (http:&#x2F;&#x2F;www.anujgakhar.com&#x2F;2011&#x2F;12&#x2F;09&#x2F;using-macosx-lion-command-line-mail-with-gmail-as-smtp&#x2F;). But all of these require me writing my Google password in cleartext (?!).<p>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&#x27;t mind writing the pass in cleartext.<p>I figured I could open up a Gmail account just for this purpose, but that somehow feels like a bit of a hack..
======
pwg
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](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.

~~~
graffitici
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?

~~~
pwg
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.

------
mtmail
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.

------
graffitici
I also found Nilas: [https://www.nilas.com/](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?

------
garyharrower
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/](https://mandrill.com/)

~~~
jpetersonmn
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.

------
jlgaddis
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.

