Blog IndexPosts by TagHome

Email Auto Responder - inotifywait

Posted <2017-08-02 Wed 00:08> by Aaron S. Jackson.

I will be away from the office next week so I decided I would look at how auto responders work, since the university have switched to Office365. I was disappointed - there is no way to send plain text as an auto response.

I decided to write my own… Hopefully it will not respond automatically to mailing lists (it shouldn't, since mailing lists typically do not change the To header), but it may respond to newsletters.


fromaddr="Aaron Jackson <>"

inotifywait -m $base -e create -e moved_to |
    while read path action file; do
    # Read the email and extract the header.
    mail=$(cat "$base/$file" | sed '/^$/q')

    # Check to make sure that the email is being sent directly to
    # me, not to a mailing list.
    to=$(echo "$mail" | grep -ie ^CC: -e ^To: |
         grep -ie aaron.jackson -e psxasj)
    if [[ $(echo "$to" | wc -l) -eq 0 ]]; then

    # Get the sender's address and send the email.
    sender=$(echo "$mail" | grep -i ^From: | cut -b7-)
    cat ~/.vacation.msg | mail -r "$fromaddr" -s "Auto Reponder" "$sender

    echo "Auto response sent to $sender"

While testing this, I was trying to figure out why sSMTP was sending mail via the school's mail server. It turns out that it looks up the A records for mail. <network name> (i.e.

Wanting to leave a comment?

Comments and feedback are welcome by email (

Related posts:

Tags: linux

Blog IndexPosts by TagHome

Copyright 2007-2022 Aaron S. Jackson (compiled: Sun 2 Jan 00:24:10 GMT 2022)