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.

#!/bin/bash

fromaddr="Aaron Jackson <aaron.jackson@nottingham.ac.uk>"

base=~/Maildir/nottingham/INBOX/new
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
        continue
    fi

    # 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"
    done

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. cs.nott.ac.uk).

Related posts:

Tags: linux

Blog IndexPosts by TagHome

Copyright 2007-2017 Aaron S. Jackson (modified: Wed 2 Aug 00:17:24 BST 2017)