On this page
Running a Command When Receiving an Email
Introduction
There’s a very useful feature that can be easily implemented: launching a command or script when receiving an email.
Usage
Sending an Email
You can send an email in the following way:
echo "body" | mail -s "subject" test@test.com
If you want to add an attachment:
mailx bar@foo.com -s "HTML Hello" -a "Content-Type: text/html" < body.htm
Or for a binary attachment:
uuencode archive.tar.gz archive.tar.gz | mail -s "Emailing: archive.tar.gz" user@example.com
Receiving an Email
To use this procedure, edit the aliases configuration and add a line like this (/etc/aliases
):
test: "|touch /tmp/test"
When you send an email to your server with the recipient test (e.g. test@fqdn), the touch command will be executed.
Note: Don’t forget to run newaliases after making changes.
Last updated 06 May 2013, 08:32 CEST.