views:

681

answers:

3

I have a web application running on Windows IIS. This app has a database where each item has a unique key (1, 2, 3...), and a list of email addresses (among other things).

I would like users to send email to the server, using an email address that identifies the item, then have the server relay the message to the email addresses for that item. For example, if a user sends email to the following address:

[email protected]

Then the server would receive the email and pipe it to a script. The script would query the database for item 75 to get a list of email addresses, then re-send the email.

I could do this easily on a unix system using sendmail, but I have no idea if a similar setup can be accomplished on a Windows system (or if it would require additional software).

+1  A: 

You could read in email through POP3 or IMAP using a timed script. I'm also a UNIXer so I'm struggling to comprehend how something like this is so difficult, but there you have it. Here's what I reckon you should do.

  • Make a script in whatever language you like. As long as it can read from POP3 or IMAP.

  • Have Windows run the script every 5 minutes

  • Have the script access the mailbox and action any emails it needs to.

My personal preference would be to install Python, but if you're limited... I don't know. ASPNET isn't bad, but I've never used it for dirty-scripting before.

Oli
Thanks - that's one option I'm investigating. However I also need to know if it's possible to have multiple addresses like "item-1", "item-2", created on-demand. For example, could all incoming emails be dropped into a single file?
BarelyFitz
+3  A: 

Hi, (This sounds like you want to implement a feature like craigslist).

The IIS SMTP service can send email, and also accept email.

Here is what you want to do.

Configure your IIS SMTP service to accept emails for a domain (You can configure this in the properties of the IIS SMTP service, under domains). Say domain name "myserver.example.com"

Then, in your DNS server, configure a MX record that points to "myserver.example.com".

Now, when email gets sent to your IIS SMTP server, it will actually get placed in your mailroot/drop folder (you can also change this folder in the IIS SMTP Service properties).

Now that you are accepting email, the next step is to write a script that will:

1)Parse the emails.

2)Modify them accordingly (do you just want to change the "to" address?).

3)If you want to resend the emails, then you need to modify them accordingly. You will need to add a single X-Sender header, that is used to identify the email address sending the email, and a X-Receiver header, for each recipient that is going to accept the email. Here is an example email that was modified:

X-Sender: [email protected]
X-Receiver: [email protected]
X-Receiver: [email protected]
From: "jim bob" <[email protected]>
To: <[email protected]>
Subject: test
MIME-Version: 1.0
Content-Type: text/plain;
Message-ID: <024f01c9e130$b3eca500$0401a8c0@local>


test

Once you have this modified content, you will want to write it to a file in the mailroot/pickup directory. Be sure to use a unique name.

The IIS SMTP Service will come by, pickup the email, and relay it on, sending the email using the X-Sender as the MAIL FROM address, and sending it to each email address listed in each X-Receiver header.

4)Run this script as a scheduled task. Another option is to build it as a windows service, or to implement something like a filesystemwatcher, where it executes each time an email is created as a file.

5)Another option to all of this is to actually implement a SMTP Event Sink, but I think that is overkill for what you want to do, and can create more headaches, than it solves. I would only go the event sink route if I like pain.

Hopefully I didn't make that about as clear as mud.

Cheers!

Dave

dave wanta
+1  A: 

Event Sinks aren't difficult at all! In fact, there are about a dozen examples written in VBS (which runs on a Win server using WSH) which accomplish exactly what you wish to do. The OnArrival event sink runs in REAL-TIME using any computer user account you wish w/o any security risk since the message is asynchronous and doesn't report back.

This is actually a terribly easy thing to do - one of the easiest. Once set up, it never breaks either. On one server I've had one running for more than 9 years processing a few thousand incoming messages per day! I've set up about a dozen of these things - if it takes you more than a couple hours, you're doing it very wrong. If it were any easier than this on UNIX, my grandmother could be a UNIX programmer so I wouldn't go bragging that this is easier to do on a UNIX server.

Thanks Nick - if you have any links or other pointers that would be appreciated.
BarelyFitz