I have a CentOS 6.3 server. I would like to create an email address like, for example, list@myserver.com that will be a special kind of email that will trigger a script.

For example: suppose I mail list@myserver.com and the subject is an IP address. I want the server to receive that mail, extract that IP from the subject and append it to a file.

How is this done on Linux? Can you guys tell me how this can be done?

2 Answers 2


You need a server that handles incoming mail, and a client which interprets that mail.

As a start:

  1. Install postfix or a similar MTA;
  2. Configure it to handle any mail it receives to its hostname locally;
  3. Either add a Postfix hook, or use something like inotifywait to wait for new mail and run your script on its arrival.

There are two things involved with doing this:

  1. How to get the email to the system
  2. process the email to append info to a file

The first you can solve by having the mail be sent to the server directly, but if the server is not online all the time (located at home), it is probably better to have the emails sent to some Google or Yahoo account and fetch them from there. You can do that with fetchmail, and have the mail delivered locally to a user list.

For the second part you can use procmail, with specific rules for the user in ~/.procmailrc. The local mail delivery agent needs to be told to use procmail e.g. in postfix you add:

mailbox_command = procmail -a "$EXTENSION"

to your /etc/postfix/main.cf file.

In the file ~list/.procmailrc you can specify rules on what to do with mail (all mails arriving there, or the ones with specific characteristics (subject, from address, etc)). procmail has several useful build in actions, and if those do not suffice you can pipe the mail into a program to do something specific it cannot do.

  • very good!!!! Thanks I will research that!
    – Duck
    May 23, 2013 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.