I have an console application and I installed mailkit package for messaging purposes.
I have code in the main method to test mailkit smtp client. I have smtp4dev dummy server running and the client code is the example code of mailkit in github with the authentication part commented, the host is localhost and the port 26, matching the smtp4dev configuration.
When the client code is executed the smtp4dev stop running
and an unhandled exception occurrs, IOException: Unable to read data from the transport connection: an existing connection was forcibly closed by the remote host.
How can I configure smtp4dev to receive message from mailkit client?
Navigate to System administration > Setup > Email parameters and click the Configuration tab, then set Batch email provider to SMTP. Next, click the SMTP settings tab. Here we need to enter parameters for smtp4dev as follows: Set Outgoing mail server to localhost and SMTP port number to 25.
C# send simple mail with Mailkit Net. Smtp; using MailKit. Security; using MimeKit; var host = "smtp.mailtrap.io"; var port = 2525; var username = "username"; // get from Mailtrap var password = "password"; // get from Mailtrap var message = new MimeMessage(); message.
After some trial and error, I was able to have success with the following arrangement.
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", "[email protected]"));
message.To.Add(new MailboxAddress("Alice", "[email protected]"));
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 that cannot access imgur:
Domain Name: localhost
Listen Interface: 0.0.0.0
Port Number: 25 (Though, in Dalsier's case, Dalsier would use 26)
Extensions:
SSL/TLS Certificate: None
SSL/TLS Certificate Password: None
Max Message Size (bytes): 0
Receive timeout (ms): 30000
Options:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With