Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP relaying in C#?

Tags:

c#

smtp

I need to create a Windows service that can listen for SMTP.

When it receives an email I need to process it, and then forward it to my real SMTP server for sending proper.

Can anyone point me at any useful source code, libraries or tutorials on how I can get started doing this?

Seems like all I need is a simple TCP listener and message parser, then I can simply resend the message with the .NET SmtpClient API?

like image 887
Andrew Bullock Avatar asked Jan 24 '23 01:01

Andrew Bullock


2 Answers

I don't know your entire requirements, but the IIS SMTP service can save incoming email to the /Drop directory. Rather than having to write a full blown TCP/IP service, you could just write a file monitoring service that monitors the /Drop directory for new emails, parses them, and performs your custom action on them.

like image 58
dave wanta Avatar answered Jan 25 '23 16:01

dave wanta


Eric Daugherty has a C# email server on sourceforge. This will do the server. To forward the messages to another SMTP server the default System.Net.Mail.SmtpClient class can be used.

Or you write a custom transport binding element for WCF (joking).

like image 25
Marc Wittke Avatar answered Jan 25 '23 14:01

Marc Wittke