SMTP relaying in C#?
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 SmtpClie开发者_C百科nt API?
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.
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).
You probably want to check this link. The article states that "The MailServerComponent implements POP3 and SMTP (core) servers. It Handles lowlevel POP3 and SMTP commands and raises events according to it. The MailServer service just handles MailServerComponent events and does mail retrieving and storing job.". It could, at least, serve as a starting point for you.
And you are right, you can implement you own (TCP) socket listener that handles and processes all required SMTP messages. Check the protocol specs here.
精彩评论