Search code examples
c#socketsunit-testingemailpop3

C# custom mail server: receive email through socket on local machine


I'm writing unit testing for email validation. I'm trying to write a very simple POP3 email listener (using sockets) so the email can be sent to my local machine using something like test@hostnameofmymachine.

I tried to do something like this: https://msdn.microsoft.com/en-us/library/kb5kfec7%28v=vs.110%29.aspx

But I don't know on which port the email will be sent so I can't create a socket unless I know which port to listen to.

How can the SMTP server (which sends the message) can know on which port to send the email? (IMAP 143? 993?) (POP3 110? 995?) So I don't know on which port I must listen to.

How can the SMTP know whether the receiver is POP3 or IMAP? How can it know whether SSL is supported?

I'm quite sure I'm missing some important information regarding email protocol.


Solution

  • POP3 and IMAP do not receive email, they only allow access to stored emails.

    You need to write an SMTP server, not a POP3 server.