Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Send mail via cron job with an overly-protective ISP UNIX
I recently got a new ISP after a house move, and have always had a cron job running to back up my files each day to an online server. Previously, I would have this job (rsync) run and pipe the output automatically to the mail command, which would throw it out to my inbox, allowing me to automatically see if there was anything wrong with the sync.

With my new ISP, they have this annoying habit of blocking any emails that look like they are coming from an SMTP server that is not their own. Obviously, so they do not get spammers blacklisting them, and hence not even their SMTP servers would be allowed to send mail, or their mail would not be accepted. This poses an issue for tech savvy people who may know what they are doing, but are being punished for knowing how things work.

Hence, I stopped getting my emails to say how the sync had gone. After getting annoyed by this, I started to look into it further. It seemed that if I was on a different network, for example my university one, and the job ran, the email would not get through -- at least not until I got home, at which point I would receive the email (the other network was blocking all smtp email; it is smarter than my ISP).

After examining the headers of the email I did receive, I noticed that the "from" address was not the normal root@robs-powerbook.local, but had rather taken on the domain of the network I was on. You can see where this is going. If you use the -r command in the mail command when piping information to it in cron, you will get a senders address that you specify. So here is my modified command (line breaks added for readability; enter as one long line):
sh /Users/rob/bin/backupjoyent.sh 2>&1 | 
mail -s "Daily Backup to joyent report" my@domain.name 
-r sender@address.here
If you set the two email addresses to be the same thing, i.e. the email address you want to send to, you should get an email from yourself every time it is run. This may not work on all hosts, but it may help with some!
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[14,724 views]  

Send mail via cron job with an overly-protective ISP | 9 comments | Create New Account
Click here to return to the 'Send mail via cron job with an overly-protective ISP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Send mail via cron job with an overly-protective ISP
Authored by: Pedro Estarque on Mar 12, '07 08:43:39AM

The -r flag seems undocumented, at least at man mail.
great, certainly useful option



[ Reply to This | # ]
Send mail via cron job with an overly-protective ISP
Authored by: jsdetwiler on Mar 12, '07 06:45:25PM

I believe that the -r is a sendmail option, and mail just passes it along to sendmail. If you look at the man page for sendmail, you'll see it documented there. That is probably why it has to be at the end of the command.



[ Reply to This | # ]
Send mail via cron job with an overly-protective ISP
Authored by: Pedro Estarque on Mar 12, '07 08:57:41AM
by the way, you can also use SendEmail http://caspian.dotconf.net/menu/Software/SendEmail/
a very powerful perl script that supports lots of smtp and ISPs idiosyncrasies

[ Reply to This | # ]
Send mail via cron job with an overly-protective ISP
Authored by: rockmanac on Mar 12, '07 09:40:07AM

I haven't hacked around with this on my powerbook at all since I either use Thunderbird or Gmail's web interface, but I have a Linux box that I configured Postfix to send e-mail through my pobox.com account's SMTP server via port 587 as the ISP has a port 25 restriction enabled.

-A

---
"Communication is an ongoing, dynamic process between an infinite
number of variables with no beginning, middle or end."
-- Dr. Ken Ksobiech, Comm. Prof.



[ Reply to This | # ]
-r must be last argument
Authored by: giskard22 on Mar 12, '07 10:21:24AM
I did some testing, and it appears the -r argument must be the last one. If you do:
echo "test" | mail -s test -r me@me.com someone@someone.com
...you get an error.

[ Reply to This | # ]
-r must be last argument
Authored by: robelkin on Mar 12, '07 04:25:34PM

Totally, i noticed this as well, I forgot to include it in the hint tho. Nice catch!



[ Reply to This | # ]
Send mail via cron job with an overly-protective ISP
Authored by: ossiejnr on Mar 12, '07 11:48:29AM

I had problems with send mail via the "mail" command and found a very useful PHP script which does the same thing but sets the reply address. I copied this off another website, but can't remember where, so credit to the author.

#!/usr/bin/php
<?php
$to = $argv[1];
$subject = $argv[2];
$msg = "";
while (!feof(STDIN)) {
$msg .= fgets(STDIN);
}
$header = "From: insert from address here\r\n";
mail($to,$subject,$msg,$header);
?>



[ Reply to This | # ]
Send mail via cron job with an overly-protective ISP
Authored by: pwestbro on Mar 12, '07 01:14:26PM

This will not work in all cases. Where the isp is blocking all outgoing traffic on port 25, changing the sender will not solve the problem.

Most likely, these isp also offer their own smtp relay to send mail. All you will need to to is configure Sendmail or Postfix to send all outgoing mail through that relay.



[ Reply to This | # ]
Send mail via cron job with an overly-protective ISP
Authored by: robelkin on Mar 12, '07 04:23:34PM

Yeah, you are correct, you can use a setting for postfix as so:

fallback_relay="isp_smtp.name.here"

This will not however for in the instance above as the mail command does not use postfix, i dont think?



[ Reply to This | # ]