I am writing a Bash shell script for Mac that sends an email notification by opening an automator application that sends email out with the default mail account in Mail.app. The automator application also attaches a text file that the script has written to. The problems with this solution are
- It is visible in the GUI when sending
- It steals focus if Mail is not the current application
- It is dependent on Mail.app’s account setup being valid in the future
I figure to get around those shortcomings I should send the mail directly from the script by entering SMTP settings, address to send to, etc. directly in the script. The catch is I would like to deploy this script on multiple computers (10.5 and 10.6) without enabling Postfix on the computer. Is it possible to do this in the script so it will run on a base Mac OS X install of 10.5. and 10.6?
Update: I’ve found the -bs option for Sendmail which seems to be what I need, but I’m at a loss of how to specify settings.
Also, to clarify, the reason I’d like to specify SMTP settings is that mails from localhost on port 25 sent out via Postfix would be blocked by most corporate firewalls, but if I specify the server and an alternate port I won’t run into that problem.
Previously, this answer was based on the default inclusion of a recent Python on Mac OS X. Since then, the Python ecosystem has evolved and Python is not available on a clean install. This answer has been updated for modern systems, but is much more involved and exceeds the scope of the original poster’s request.
Python and it’s built-in standard library provides some nice facilities for sending email if you’re willing to install it. Consider using the stock installer or installing homebrew followed by
brew install python.From there, customize the following script based on stock examples to suit your needs.
I hope this helps.