1

I currently have the need to set up an outgoing SMTP server with an extra twist to it. If a user sends an email and this server receives the mail then it should validate the the email address that the message was sent from to a SQL database.

i.e: I have a table with email addresses and a status column for ACTIVE/INACTIVE. A user sends an email and it gets sent to the SMTP server. When the email is received by the SMTP server, the server should take the email address that the mail has been sent from and validate it against the database to check the email address's corresponding status. If that status is active then the message should relay to the to address. If not, a reply message should be sent to that email address stating that the email is inactive.

My question is thus. Will it be best to write my own SMTP server app in C# that does this or is there a sort of an out of the box solution such as IIS that I can set up some how to get this functionality?

Re-writing my own email server app in C# seems like a dirty solution and a recreation of the wheel?

I read something about OnArrival functionality on an IIS SMTP server that can take scripts. Any thoughts on that?

Jason Geiger
  • 1,912
  • 18
  • 32
Joachim Prinsloo
  • 618
  • 3
  • 12
  • 31
  • what are you using to cominicate all of this meaning db, smtp and why can't you create a class that would handle the validation why write your own SMTP – COLD TOLD Dec 02 '12 at 06:31
  • Possible duplicate of [Pipe incoming email to a script on Windows IIS SMTP?](https://stackoverflow.com/questions/926345/pipe-incoming-email-to-a-script-on-windows-iis-smtp) – halfer Jun 13 '18 at 14:57
  • I would use hMailServer for this. Don't reinvent the wheel. – Jason Geiger Jun 13 '18 at 15:20

1 Answers1

1

I think this is what will help you up:
Pipe incoming email to a script on Windows IIS SMTP?

Part from answer:

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?).

Here is the trick, so you need to parse the incoming emails and forward only those which validate the email.. and which do not pass the validation, read the "FROM" address from email and reply him!

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: me@mywebsite.com X-Receiver: recip1@theirdomain.com X-Receiver: recip2@theirdomain.com From: "jim bob" To: 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.

Community
  • 1
  • 1