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.
  • 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. Commented May 15, 2011 at 17:24

2 Answers 2


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.


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: [email protected]. Another approach would be to create ~/.forward containing [email protected], 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.

  • He already has sendmail which also supports smart hosts, aliases and authentication.
    – Mel
    Commented May 18, 2011 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
    Commented May 19, 2011 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .