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

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.

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.

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 (you+extension#example.com go to you#example.com)
Docker Mail Server
https://github.com/docker-mailserver/docker-mailserver

Related

Is it possible to send emails from any type of email using common smtp host?

i used Simple Mail Transfer Protocol gmail host to send emails from gmail it works fine.but when try to send email from yahoo or outlook it doesn't work. Is it Possible to send emails from all type of mails like yahoo,outlook etc in Simple Mail Transfer Protocol using common Simple Mail Transfer Protocol host in c# ?
Yes, C# has built in support for sending emails using any standard SMTP server
If your question is more about why gmail and outlook didn't work when you tried you'll need to include more detail such as error messages. As long as gmail/outlook do provide an accessible and protocol compliant SMTP service on your country/to your location, and you're using it in accordance with their instructions/you're properly authenticating with an account that has access, and they aren't classifying your mail as spam then the mail should be sent as with any other SMTP service
https://support.google.com/a/answer/176600?hl=en
https://support.office.com/en-us/article/pop-imap-and-smtp-settings-for-outlook-com-d088b986-291d-42b8-9564-9c414e2aa040

Force SMTP server to only send mail via TLS

I'm developing an ASP.NET MVC application that needs to transmit sensitive information via email. I'm aware of using S/MIME to encrypt the email contents end-to-end, but I cannot use it for various reasons. I also realize, however, that the emails would be sent in plain-text from the web host's SMTP server to the destination email servers, opening up a serious man-in-the-middle vulnerability. Therefore, I need to ensure that the outgoing SMTP server will transmit a message ONLY IF it can establish a TLS/SSL connection with the destination mail server.
I've been searching for a while and can't even figure out where in the process that decision is made. Most answers address enforcing TLS between the application and the SMTP server, which I've already solved. Can anyone shed some light on this? Thanks.
What you are trying to do is not possible. Once you've submitted the mail to the mail server you've lost control over it. There is no way to instruct the server (and all following server in the path) to only deliver the mail with TLS.

Sending Mail over proxy server

I am using a LAN network, which uses a proxy server. In C#, I am trying to develop an application through which I can send E-mails. But from my network, I can't send mail due to this proxy issue. From any other network, not dependent on proxy server, there is no problem to send mail.
I typed in command prompt, telnet smtp.gmail.com 25
and it displays it can't connect to 'smtp.gmail.com'
It sounds like your proxy is explicitly denying the gmail.com domain (if its a corporate network then many do). Can you reach gmail.com in your browser (if you can't this may put up a nasty looking alert from your systems guys).
There are a couple of ways round this:
Get smtp.gmail.com, or port 25 to smtp.gmail.com, unblocked on the proxy.
Get an smtp relay put in place instaed of using smtp from gmail. There's some info on this here.
Either way, time to go and be nice to your sys admins!

how to create a SMTP server

I have an application that run on server,
I want that my application could received mail in order to start some function.
I would like to know what should I need to do in order to have this capability?
Do I need to build SMTP server? if so, how should I do it?
You can try: http://www.lumisoft.ee/lsWWW/download/downloads/ .
There is SMTP server component what you can use to recieve emails.
Or alternatively there is SMTP server written in C#, you can write message filter for server.
In filter you can access incoming message and do what ever you want with it.
--- Yes also as others suggested will work ok too, you just run simple mail server and get emails by pop3 or imap. Pop3 and Imap components and example applications also included in same link.
You can use IIS6 to receive email and drop it into a specified folder. Your app can then pick up those emails and do whatever it needs to with them.
Active the SMTP service in IIS. It drops emails in the C:\inetpub\smtproot\drop folder IIRC.
Then you just need a Mime parser to read the EML files. I used the one in Lumisoft when I did the same thing.
You could use any Mailserver to receive the mail and have your application check the poxtbox every 1 minute to receive the mails.
When any mail arrived (or special subject as you need), you could execute your code.
For IMAP you could look at this Library
I have previously had some success using the Chilkat POP3 component to programmatically monitor a POP3 account for incoming mail.

Send an email using exchange server ONLY

I need to send an email in my C# project using my companies Exchange Server.
Because someone sent out thousands of Emails from my company using a self hosted server, any attempts to not use the company Exchange Server to send the email will be squished.
I imagine I am going to need to get an Active Directory user created to do this... but what code to use? How to do the sending?
You can send email through Exchange using SMTP with .Net's SmtpClient class.
You will need a login for the server.
You could use the System.Net.Mail classes to send the email via SMTP if that is enabled on your SMTP server. Alternatively you could use the webdav protocol to send the email via HttpRequests and HttpResponses. An example showing how to do this can be found here.

Categories

Resources