'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 1:[1]
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.
Solution 2:[2]
I recommend you to use this repository, it contains in itself most of the services you may need and it is easy to configure.
In our case we use the services:
- Postfix with SMTP.
- Dovecot for POP3.
- SpamAssassin with custom rules.
- OpenDKIM
- OpenDMARC
- LetsEncrypt and self-signed certificates
- Persistent data and state
- CI/CD
- Extension Delimiters ([email protected] go to [email protected])
Docker Mail Server https://github.com/docker-mailserver/docker-mailserver
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | jstedfast |
Solution 2 | Ayham Al Chouhuf |