The first thing to note is that my email supports sub-addressing. This means that in the above email address, the mail is delivered to “reed” with argument “2009b”. I use this argument to determine that the sender is looking for a PDF reprint of my recent paper.
Next I had to modify my
.procmailrc to copy 2009b requests to a specific folder and reply to them with the paper. Here is my solution, which is based somewhat on the solution for vacation notice emails with Procmail.
PLUS=$1 #copy the sub-address into variable PLUS
* PLUS ?? ^2009b$
* !^X-Loop: reed+2009b@[snip]
* !^X-Spam-Status: Yes
| (formail -r -A"From: reed@[snip]" -A"X-Loop: reed+2009b@[snip]" \
-I"MIME-Version: 1.0" \
-I"Content-Type: multipart/mixed; boundary=\"------------070504020300020208040609\""; \
cat $HOME/papers/2009b.msg ) | $SENDMAIL -oi -t
This solution will copy and auto-reply to the incoming email if it matches the +2009b argument, is not from an email list, has not already been auto-replied to, and is not spam.
To send the reply, I use the
formail tool that comes with Procmail to construct the reply. This involves using flags to specifying some email header variables, followed by catting a prespecified email body that contains the encoded attachment. I generated the body by sending myself the email and attachments that I wanted to send out to people, and then copying the body of the message to a text file, 2009b.msg. I just had to copy the boundary header used by my email program to the formail recipe above.
This rule can be expanded to autorespond to multiple requests and to handle formail or sendmail errors.