I have some programs ported over from Solaris that generate emails and send them using /usr/bin/mail. However, to get /usr/bin/mail to work, you have to activate sendmail or a sendmail replacement like
postfix (found in Fink). Sendmail configuration is a real pain, so I wrote this Perl script.

The script is a drop-in replacement for /usr/bin/mail that uses AppleScript to tell Mail.app to send the mail. Save it somewhere in your path (I put it in ~/bin/mail) and invoke in the terminal with mail -s.

The body of the message is read from standard input. The script takes all the options /usr/bin/mail does, ignoring those that aren't applicable. I've added a new option -F to allow the user to set the From: address. There's also an option to set the Reply-To: address, but Mail.app doesn't like the AppleScript I generate for it (anyone know why?). I think the script can be easily adapted to behave like sendmail rather than mail, but I haven't attempted this.

[robg adds: I haven't tested this one ... I did, however, copy and paste the script from the above link into the remainder of this hint, just in case the parent site ever vanishes.]

Great! I have used self-emailed status reports from all kinds of unix platforms and I have missed having this ability -- but not enough to solve the sendmail problems. I tested your script and it works fine on my ibook.

My understanding is that root and other system users will send alerts through email. I've wanted to see those alrerts, but not badly enough to enable sendmail, as you say. Will this method allow those alerts to be sent?

I assume it wouldn't work if I were logged out, but I'm just using the script on my Powerbook,
where I'm the only user and I'm always logged in.
I think if you're
running a server, you should just bite the bullet and configure
sendmail or postfix.

Since php is executed as a different user I think, that it can't connect to my mail.app. Is there a way to connect to a special app of a special user on the local machine?

In terminal.app I'm also only able to run the app with "echo "testbody" | /usr/local/scripts/mail.pl -v -s testsubject truhe@metal.de" - everything else hangs after typing in the subject. Does any one of you know the correct syntax for the php.ini?

I don't like the sudoers thing... it opens my machine in a way I don't want...

In another hint someone added an applescript as a comment. within the first lines there was a call to another applescript, running on a remote machine with another username and password which also works on the same machine. this would solve the problem. unfortunately, I was not able to find this script :(

I see many people talk about 'risk' when using sudo with NOPASSWD: and I agree, when applied broadly it is a little silly. However, sudo has very fine grained control over who can do what and as whom (either with or without a password).

This allows user to run /path/to/some/program_or_script as user_to_run_as on localhost with no password. You can include muliple users in the parentheses and even exclude users by preceding the username with a !, i.e. (ALL, !root) means all users except root.

This, IMO, certainly beats having scripts with passwords hardcoded into them in cleartext.

A wonderful overkill solution I use to solve this problem: install a trail version of CommuniGate Pro. (The trail version works forever, legally, just adding a "Sent by trail version of CGP" line to each message).

- CGPro is a relatively small (3.4MB) download <http://www.stalker.com/CommuniGatePro/#Current>
- very easy to install (standard package, no compiling or commandline configuration)
- uses almost no resources (even under heavy load!)
- will work fine for multiple logged in users
- but doesn't need the "GUI-login", Mail.app, or Applescripts

Installing it disables sendmail, archives the commandline "mail" and installs a drop-in replacement for it. (And you can also send mail by putting correctly formatted files in the Submitted directory.)

CGPro is configured through a webinterface; all you need to do in this case is disable external mail relay (as with any mailserver!). Like I said, it's overkill: SMTP/POP/IMAP/Webmail/Listserver and lots more... but it works fine, sending me status mails from multiple servers, doing nothing else...

Hey thanks for the CGPro hint. I just installed it on my server and after 1 minute of set up I have it up and running perfectly. It seems to have a great un-installer script which gave me the confidence to install it. 10x easier then sendmail, or even that mail.app script.

With the help of (http://www.macosxhints.com/article.php?story=20030205064206934&query=introduction+to+find) a previous hint, I piped a search for all files greater than 1 GB in size to this mail script: