Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have some home system monitoring scripts run via cron that will create output, and hence mail to the user that runs the script. I want to redirect this mail to my Gmail (or insert any other third-party mail) account.

The method should

  1. be able to authenticate with and use another SMTP server (e.g. Gmail's SMTP itself) rather than sending directly via sendmail etc, as services like Gmail are likely to mark my mail as spam if I don't use a legit service.
  2. retry sending if failed as it will be run via a home Internet connection.
share|improve this question
    
is your machine running a mail server locally you can send mail to for forwarding to the outside? I think this is pretty standard for Linux. Often mail servers on desktop machines without static IPs (eg on cable internet) set up their local mail servers to send their mails to a smarthost, and have everything send their mail to the local mail server. Retry is usually automatically done by the smarthost for a period of time, I believe 4 days or so. Of course, you could bypass the local mail server entirely. In any case, mail is commonly used for scripts. –  Faheem Mitha May 15 '11 at 17:24
add comment

2 Answers

Install a local MTA, such as exim, and configure it to use a smarthost, in this case either your ISP's mail server or google's (the latter possibly better if you are concerned about the SMTP reputation of your home IP).

Then, set up forwarding for your user. There are many ways to do this. With exim on Debian, you can edit /etc/aliases and set foo: foo@gmail.com. Another approach would be to create ~/.forward containing foo@gmail.com, but that means your $HOME needs to be available at the time mail is sent (not always the case for me, my $HOME is only mounted on log in).

A good MTA (such as exim) will support smarthosts and also do retries.

share|improve this answer
    
He already has sendmail which also supports smart hosts, aliases and authentication. –  Mel May 18 '11 at 11:48
    
It's not clear that he does have sendmail; merely that he's familiar with it and doesn't think it can solve his problem. –  jmtd May 19 '11 at 12:32
add comment

One very simple way to do this (and it may not meet all your requirments, it's so simple) is to use a .forward file in the $HOME directory of the user ID that runs the cron job.

You just put a 3rd party email address in .forward, and it appears that sendmail does the rest.

You can use .forward to run the email through a program. My .forward file says this: "|exec /usr/bin/procmail"

procmail is a fairly primitive mail filtering program that works well enough for me.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.