Recommended way to use smtp4dev as the mailkit client message server

I have a console application and I installed the mailkit messaging package.

I have the code in the main mailkit smtp client validation method. I have a running smtp4dev server, and the client code is a sample mailkit code in github with comment on the verification side, the host is localhost and port 26, matching the smtp4dev configuration.

When the client code executes, smtp4dev stops stop running and an unhandled exception occurs, IOException: Unable to read data from the transport connection: an existing connection was forcibly closed by the remote host.

How to configure smtp4dev to receive a message from the mailkit client?

+6
source share
2 answers

After some trial and error, I was able to succeed in the following order. smtp4dev options

My code is similar to https://github.com/jstedfast/MailKit#sending-messages :

 public void DoMail() { var message = new MimeMessage(); message.From.Add(new MailboxAddress("Joey", " joey@friends.com ")); message.To.Add(new MailboxAddress("Alice", " alice@wonderland.com ")); message.Subject = "How you doin?"; message.Body = new TextPart("plain") { Text = @"Hey Alice, What are you up to this weekend? Monica is throwing one of her parties on Saturday and I was hoping you could make it. Will you be my +1? -- Joey " }; using (var client = new SmtpClient()) { // For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS) client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("localhost", 25, false); // Note: since we don't have an OAuth2 token, disable // the XOAUTH2 authentication mechanism. client.AuthenticationMechanisms.Remove("XOAUTH2"); // Note: only needed if the SMTP server requires authentication //client.Authenticate("joey", "password"); client.Send(message); client.Disconnect(true); } } 

For those who cannot access imgur:
Domain Name: localhost
Listen to the interface: 0.0.0.0
Port Number: 25 (Although, in the case of Dalser, Dalsier will use 26)
Extensions:

  • [] Implicit SSL / TLS
  • [x] 8BITMIME
  • [] STARTTLS
  • [] AUTH
  • [x] SIZE

SSL / TLS Certificate: No
SSL / TLS Certificate Password: None
Maximum message size (bytes): 0
Receive Timeout (ms): 30000
Options:

  • [] Require authentication
  • [] Require a secure connection
  • [] Only allow text authentication over a secure connection.
+8
source

You have client.Disconnect(true); ? The error message suggests that you do not.

0
source

All Articles