Send mail with Gmail SMTP using MailKit SMTP Client in .NET core 2.2 is not working for meNo connection could be made because the target machine actively refused it 127.0.0.1:3446Sending email in .NET through GmailSending email through Gmail SMTP server with C#Send email using the GMail SMTP server from a PHP pageASP.NET fails to send email through Gmail SMTP, but Outlook 2007 succeedsAsp.net mail sending + from id is over written by smtp user idWe do not relay non-local mail,Mailbox name not allowed. What does it meanSending mails via SMTP using WordPress on 000webhostsmtp.gmail.com vs ssl://smtp.gmail.com while sending email using gmail smtp serverWeird Issue in dotnet core website using MailKit to send emailSystem.MissingMethodException When Sending Email using MailKit In Xamarin.Forms

Fancy String Replace

How to avoid using System.String with Rfc2898DeriveBytes in C#

Are illustrations in novels frowned upon?

Is it appropriate for a prospective landlord to ask me for my credit report?

How to stop this icon from appearing on the taskbar?

What is the purpose of consecutive ADC instructions to a single register?

Earth rotation discrepancy

Are there any music source codes for sound chips?

Why is my Earth simulation slower than the reality?

What is the hex versus octal timeline?

What is the appropriate benchmark for a Long/Short VIX futures strategy?

Why is less being run unnecessarily by git?

Why is Boris Johnson visiting only Paris & Berlin if every member of the EU needs to agree on a withdrawal deal?

Is it safe to remove the bottom chords of a series of garage roof trusses?

Do AT motherboards (286, 386, 486) really need -5V (besides redirecting it to ISA connectors)?

How should I face my manager if I make a mistake because a senior coworker explained something incorrectly to me?

A more intelligent ntile

Why were movies shot on film shot at 24 frames per second?

Why does The Ancient One think differently about Doctor Strange in Endgame than the film Doctor Strange?

How is "sein" conjugated in this sub-sentence?

Defense against attacks using dictionaries

Nth Problem with TikZ and Extensive Form Games

Is “I am getting married with my sister” ambiguous?

Why don't we use Cavea-B



Send mail with Gmail SMTP using MailKit SMTP Client in .NET core 2.2 is not working for me


No connection could be made because the target machine actively refused it 127.0.0.1:3446Sending email in .NET through GmailSending email through Gmail SMTP server with C#Send email using the GMail SMTP server from a PHP pageASP.NET fails to send email through Gmail SMTP, but Outlook 2007 succeedsAsp.net mail sending + from id is over written by smtp user idWe do not relay non-local mail,Mailbox name not allowed. What does it meanSending mails via SMTP using WordPress on 000webhostsmtp.gmail.com vs ssl://smtp.gmail.com while sending email using gmail smtp serverWeird Issue in dotnet core website using MailKit to send emailSystem.MissingMethodException When Sending Email using MailKit In Xamarin.Forms






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm using NLog an target to send log to some emails using smtp.google.com:587 SMTP server. When I'm using standard System.Net.Mail.SmtpClient library it's working without any problems but when using MailKit it throw me error:




Error sending mail. Exception: >System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (10061): .No connection could be made because the target machine actively refused it .>[::ffff:173.194.76.108]:587




I added one solution with two console projects. One using MailKit and other System.Net.Mail. All settings parameters looks are the same but it doesn't work in MailKit:



using System;
using System.Diagnostics;
using MailKit.Net.Smtp;
using MailKit;
using MailKit.Security;
using MimeKit;

namespace SendMailKit

class Program

public static void Main(string[] args)

Console.WriteLine("Create message");
var message = new MimeMessage();
message.From.Add(new MailboxAddress("GTS", "tfs.gettaxsolutions@gmail.com"));
message.To.Add(new MailboxAddress("Me", "info@gettaxsolutions.com"));
message.Subject = "Test mail";
message.Body = new TextPart("plain")

Text = @"Hello, This is the test"
;

Console.WriteLine("Create SMTP client");
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;
Console.WriteLine("Connect");
**client.Connect("smtp.gmail.com", 587, true);**
Console.WriteLine("Authenticate");
client.Authenticate("tfs.gettaxsolutions", "*********");
client.Connected += Client_Connected;
client.Disconnected += Client_Disconnected;
client.Authenticated += Client_Authenticated;
client.MessageSent += Client_MessageSent;
Console.WriteLine("Send Message");
client.Send(message);
Console.WriteLine("Disconnect");
client.Disconnect(true);


Console.ReadLine();


private static void Client_MessageSent(object sender, MessageSentEventArgs e)

Console.WriteLine("MessageSent");


private static void Client_Authenticated(object sender, AuthenticatedEventArgs e)

Console.WriteLine("Authenticated");


private static void Client_Disconnected(object sender, DisconnectedEventArgs e)

Console.WriteLine("Disconnected");


private static void Client_Connected(object sender, ConnectedEventArgs e)

Console.WriteLine("Connected");





And this throw the same exception like this one in NLog. the exception is in client.Connect("smtp.gmail.com", 587, true); So the problem is in the MailKit connect. In other project which using System.Net.Mail everything is working fine and the mail is sent successful. I'm starting them on same machine, same environment just change the startup point of console application to test (so the connectivity is not a problem):



using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace SendSimpleMail

public class Program

static bool mailSent = false;
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

// Get the unique identifier for this asynchronous operation.
String token = (string)e.UserState;

if (e.Cancelled)

Console.WriteLine("[0] Send canceled.", token);

if (e.Error != null)

Console.WriteLine("[0] 1", token, e.Error.ToString());

else

Console.WriteLine("Message sent.");

mailSent = true;

public static void Main()

// Command-line argument must be the SMTP host.
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("tfs.gettaxsolutions", "***********");
// Specify the email sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("tfs.gettaxsolutions@gmail.com", "GTS");
// Set destinations for the email message.
MailAddress to = new MailAddress("info@gettaxsolutions.com", "Me");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test email message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] 'u2190', 'u2191', 'u2192', 'u2193' );
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)

client.SendAsyncCancel();

// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");





I can't find what is the issue with MailKit. The settings looks like identical. Do you have some idea what can be a problem? Is it bug or have some problem in my settings?



MailKit have to send email successful



ASP.NET Core 2.2, MailKit 2.1.3










share|improve this question


























  • Check out the accepted answer to a similar question here: stackoverflow.com/questions/9695224/…

    – jstedfast
    Mar 28 at 12:04

















1















I'm using NLog an target to send log to some emails using smtp.google.com:587 SMTP server. When I'm using standard System.Net.Mail.SmtpClient library it's working without any problems but when using MailKit it throw me error:




Error sending mail. Exception: >System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (10061): .No connection could be made because the target machine actively refused it .>[::ffff:173.194.76.108]:587




I added one solution with two console projects. One using MailKit and other System.Net.Mail. All settings parameters looks are the same but it doesn't work in MailKit:



using System;
using System.Diagnostics;
using MailKit.Net.Smtp;
using MailKit;
using MailKit.Security;
using MimeKit;

namespace SendMailKit

class Program

public static void Main(string[] args)

Console.WriteLine("Create message");
var message = new MimeMessage();
message.From.Add(new MailboxAddress("GTS", "tfs.gettaxsolutions@gmail.com"));
message.To.Add(new MailboxAddress("Me", "info@gettaxsolutions.com"));
message.Subject = "Test mail";
message.Body = new TextPart("plain")

Text = @"Hello, This is the test"
;

Console.WriteLine("Create SMTP client");
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;
Console.WriteLine("Connect");
**client.Connect("smtp.gmail.com", 587, true);**
Console.WriteLine("Authenticate");
client.Authenticate("tfs.gettaxsolutions", "*********");
client.Connected += Client_Connected;
client.Disconnected += Client_Disconnected;
client.Authenticated += Client_Authenticated;
client.MessageSent += Client_MessageSent;
Console.WriteLine("Send Message");
client.Send(message);
Console.WriteLine("Disconnect");
client.Disconnect(true);


Console.ReadLine();


private static void Client_MessageSent(object sender, MessageSentEventArgs e)

Console.WriteLine("MessageSent");


private static void Client_Authenticated(object sender, AuthenticatedEventArgs e)

Console.WriteLine("Authenticated");


private static void Client_Disconnected(object sender, DisconnectedEventArgs e)

Console.WriteLine("Disconnected");


private static void Client_Connected(object sender, ConnectedEventArgs e)

Console.WriteLine("Connected");





And this throw the same exception like this one in NLog. the exception is in client.Connect("smtp.gmail.com", 587, true); So the problem is in the MailKit connect. In other project which using System.Net.Mail everything is working fine and the mail is sent successful. I'm starting them on same machine, same environment just change the startup point of console application to test (so the connectivity is not a problem):



using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace SendSimpleMail

public class Program

static bool mailSent = false;
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

// Get the unique identifier for this asynchronous operation.
String token = (string)e.UserState;

if (e.Cancelled)

Console.WriteLine("[0] Send canceled.", token);

if (e.Error != null)

Console.WriteLine("[0] 1", token, e.Error.ToString());

else

Console.WriteLine("Message sent.");

mailSent = true;

public static void Main()

// Command-line argument must be the SMTP host.
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("tfs.gettaxsolutions", "***********");
// Specify the email sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("tfs.gettaxsolutions@gmail.com", "GTS");
// Set destinations for the email message.
MailAddress to = new MailAddress("info@gettaxsolutions.com", "Me");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test email message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] 'u2190', 'u2191', 'u2192', 'u2193' );
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)

client.SendAsyncCancel();

// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");





I can't find what is the issue with MailKit. The settings looks like identical. Do you have some idea what can be a problem? Is it bug or have some problem in my settings?



MailKit have to send email successful



ASP.NET Core 2.2, MailKit 2.1.3










share|improve this question


























  • Check out the accepted answer to a similar question here: stackoverflow.com/questions/9695224/…

    – jstedfast
    Mar 28 at 12:04













1












1








1








I'm using NLog an target to send log to some emails using smtp.google.com:587 SMTP server. When I'm using standard System.Net.Mail.SmtpClient library it's working without any problems but when using MailKit it throw me error:




Error sending mail. Exception: >System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (10061): .No connection could be made because the target machine actively refused it .>[::ffff:173.194.76.108]:587




I added one solution with two console projects. One using MailKit and other System.Net.Mail. All settings parameters looks are the same but it doesn't work in MailKit:



using System;
using System.Diagnostics;
using MailKit.Net.Smtp;
using MailKit;
using MailKit.Security;
using MimeKit;

namespace SendMailKit

class Program

public static void Main(string[] args)

Console.WriteLine("Create message");
var message = new MimeMessage();
message.From.Add(new MailboxAddress("GTS", "tfs.gettaxsolutions@gmail.com"));
message.To.Add(new MailboxAddress("Me", "info@gettaxsolutions.com"));
message.Subject = "Test mail";
message.Body = new TextPart("plain")

Text = @"Hello, This is the test"
;

Console.WriteLine("Create SMTP client");
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;
Console.WriteLine("Connect");
**client.Connect("smtp.gmail.com", 587, true);**
Console.WriteLine("Authenticate");
client.Authenticate("tfs.gettaxsolutions", "*********");
client.Connected += Client_Connected;
client.Disconnected += Client_Disconnected;
client.Authenticated += Client_Authenticated;
client.MessageSent += Client_MessageSent;
Console.WriteLine("Send Message");
client.Send(message);
Console.WriteLine("Disconnect");
client.Disconnect(true);


Console.ReadLine();


private static void Client_MessageSent(object sender, MessageSentEventArgs e)

Console.WriteLine("MessageSent");


private static void Client_Authenticated(object sender, AuthenticatedEventArgs e)

Console.WriteLine("Authenticated");


private static void Client_Disconnected(object sender, DisconnectedEventArgs e)

Console.WriteLine("Disconnected");


private static void Client_Connected(object sender, ConnectedEventArgs e)

Console.WriteLine("Connected");





And this throw the same exception like this one in NLog. the exception is in client.Connect("smtp.gmail.com", 587, true); So the problem is in the MailKit connect. In other project which using System.Net.Mail everything is working fine and the mail is sent successful. I'm starting them on same machine, same environment just change the startup point of console application to test (so the connectivity is not a problem):



using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace SendSimpleMail

public class Program

static bool mailSent = false;
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

// Get the unique identifier for this asynchronous operation.
String token = (string)e.UserState;

if (e.Cancelled)

Console.WriteLine("[0] Send canceled.", token);

if (e.Error != null)

Console.WriteLine("[0] 1", token, e.Error.ToString());

else

Console.WriteLine("Message sent.");

mailSent = true;

public static void Main()

// Command-line argument must be the SMTP host.
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("tfs.gettaxsolutions", "***********");
// Specify the email sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("tfs.gettaxsolutions@gmail.com", "GTS");
// Set destinations for the email message.
MailAddress to = new MailAddress("info@gettaxsolutions.com", "Me");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test email message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] 'u2190', 'u2191', 'u2192', 'u2193' );
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)

client.SendAsyncCancel();

// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");





I can't find what is the issue with MailKit. The settings looks like identical. Do you have some idea what can be a problem? Is it bug or have some problem in my settings?



MailKit have to send email successful



ASP.NET Core 2.2, MailKit 2.1.3










share|improve this question
















I'm using NLog an target to send log to some emails using smtp.google.com:587 SMTP server. When I'm using standard System.Net.Mail.SmtpClient library it's working without any problems but when using MailKit it throw me error:




Error sending mail. Exception: >System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (10061): .No connection could be made because the target machine actively refused it .>[::ffff:173.194.76.108]:587




I added one solution with two console projects. One using MailKit and other System.Net.Mail. All settings parameters looks are the same but it doesn't work in MailKit:



using System;
using System.Diagnostics;
using MailKit.Net.Smtp;
using MailKit;
using MailKit.Security;
using MimeKit;

namespace SendMailKit

class Program

public static void Main(string[] args)

Console.WriteLine("Create message");
var message = new MimeMessage();
message.From.Add(new MailboxAddress("GTS", "tfs.gettaxsolutions@gmail.com"));
message.To.Add(new MailboxAddress("Me", "info@gettaxsolutions.com"));
message.Subject = "Test mail";
message.Body = new TextPart("plain")

Text = @"Hello, This is the test"
;

Console.WriteLine("Create SMTP client");
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;
Console.WriteLine("Connect");
**client.Connect("smtp.gmail.com", 587, true);**
Console.WriteLine("Authenticate");
client.Authenticate("tfs.gettaxsolutions", "*********");
client.Connected += Client_Connected;
client.Disconnected += Client_Disconnected;
client.Authenticated += Client_Authenticated;
client.MessageSent += Client_MessageSent;
Console.WriteLine("Send Message");
client.Send(message);
Console.WriteLine("Disconnect");
client.Disconnect(true);


Console.ReadLine();


private static void Client_MessageSent(object sender, MessageSentEventArgs e)

Console.WriteLine("MessageSent");


private static void Client_Authenticated(object sender, AuthenticatedEventArgs e)

Console.WriteLine("Authenticated");


private static void Client_Disconnected(object sender, DisconnectedEventArgs e)

Console.WriteLine("Disconnected");


private static void Client_Connected(object sender, ConnectedEventArgs e)

Console.WriteLine("Connected");





And this throw the same exception like this one in NLog. the exception is in client.Connect("smtp.gmail.com", 587, true); So the problem is in the MailKit connect. In other project which using System.Net.Mail everything is working fine and the mail is sent successful. I'm starting them on same machine, same environment just change the startup point of console application to test (so the connectivity is not a problem):



using System;
using System.Net;
using System.Net.Mail;
using System.Net.Mime;
using System.Threading;
using System.ComponentModel;
namespace SendSimpleMail

public class Program

static bool mailSent = false;
private static void SendCompletedCallback(object sender, AsyncCompletedEventArgs e)

// Get the unique identifier for this asynchronous operation.
String token = (string)e.UserState;

if (e.Cancelled)

Console.WriteLine("[0] Send canceled.", token);

if (e.Error != null)

Console.WriteLine("[0] 1", token, e.Error.ToString());

else

Console.WriteLine("Message sent.");

mailSent = true;

public static void Main()

// Command-line argument must be the SMTP host.
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential("tfs.gettaxsolutions", "***********");
// Specify the email sender.
// Create a mailing address that includes a UTF8 character
// in the display name.
MailAddress from = new MailAddress("tfs.gettaxsolutions@gmail.com", "GTS");
// Set destinations for the email message.
MailAddress to = new MailAddress("info@gettaxsolutions.com", "Me");
// Specify the message content.
MailMessage message = new MailMessage(from, to);
message.Body = "This is a test email message sent by an application. ";
// Include some non-ASCII characters in body and subject.
string someArrows = new string(new char[] 'u2190', 'u2191', 'u2192', 'u2193' );
message.Body += Environment.NewLine + someArrows;
message.BodyEncoding = System.Text.Encoding.UTF8;
message.Subject = "test message 1" + someArrows;
message.SubjectEncoding = System.Text.Encoding.UTF8;
// Set the method that is called back when the send operation ends.
client.SendCompleted += new
SendCompletedEventHandler(SendCompletedCallback);
// The userState can be any object that allows your callback
// method to identify this send operation.
// For this example, the userToken is a string constant.
string userState = "test message1";
client.SendAsync(message, userState);
Console.WriteLine("Sending message... press c to cancel mail. Press any other key to exit.");
string answer = Console.ReadLine();
// If the user canceled the send, and mail hasn't been sent yet,
// then cancel the pending operation.
if (answer.StartsWith("c") && mailSent == false)

client.SendAsyncCancel();

// Clean up.
message.Dispose();
Console.WriteLine("Goodbye.");





I can't find what is the issue with MailKit. The settings looks like identical. Do you have some idea what can be a problem? Is it bug or have some problem in my settings?



MailKit have to send email successful



ASP.NET Core 2.2, MailKit 2.1.3







.net asp.net-core .net-core smtp mailkit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 16:40







GetTaxSolutions

















asked Mar 27 at 16:34









GetTaxSolutionsGetTaxSolutions

64 bronze badges




64 bronze badges















  • Check out the accepted answer to a similar question here: stackoverflow.com/questions/9695224/…

    – jstedfast
    Mar 28 at 12:04

















  • Check out the accepted answer to a similar question here: stackoverflow.com/questions/9695224/…

    – jstedfast
    Mar 28 at 12:04
















Check out the accepted answer to a similar question here: stackoverflow.com/questions/9695224/…

– jstedfast
Mar 28 at 12:04





Check out the accepted answer to a similar question here: stackoverflow.com/questions/9695224/…

– jstedfast
Mar 28 at 12:04












3 Answers
3






active

oldest

votes


















1















I just partly-solved a very similar problem merely a few minutes ago; what I learned may help you.



In the case I have, there was reliably working code for MailKit to send from application with target of NET Core 2.1.



Recently I updated all the Nuget packages, thinking it was good practice to do this. Then I later discovered that my working SMTP send code had suddenly stopped working and it was reporting identical error to what you have experienced.



With this situation I checked all kinds of problems with smtp server, firewall, etc., until I remembered the Nuget update, began experimenting and eventually downgraded MailKit to 2.0.0. The send code began working again once MailKit had the version downgrade.



I have not pinpointed the exact location and mechanism of failure but have developed some confidence that (in the case I have been working on) the MailKit version used is directly involved. For today it's restored to working on the MailKit 2.0.0 downgrade and there is more research to be done to take it beyond that status.






share|improve this answer

























  • Try setting the client.Timeout to -1 to see if perhaps the problem is a connection timeout? That's the main thing that changed between 2.0 and 2.1 (Connect became cancellable via timeout value).

    – jstedfast
    Mar 28 at 15:03











  • Will check that out. The failure was consistent connecting against two entirely different smtp servers. (And success with both servers when heading back to 2.0.) There was no code change so maybe the default taken was not good.

    – An commercial developer
    Mar 28 at 16:59











  • Hmm, just remembered I changed from doing Dns.GetHostAddresses() and then looping over each IP address returned to just having Socket.Connect (string hostname, int port). Perhaps the problem is that Socket.Connect() when given a host name isn't using the right IP?

    – jstedfast
    Mar 28 at 19:13











  • Are you on a WIndows system or a Unix-based system like Linux/MacOS? Seems there is/was(?) a bug in .NET's SOcket logic when connecting via a hostname instead of an IPAddress because Linux/MacOS can't reuse sockets.

    – jstedfast
    Mar 29 at 10:32











  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17


















0















I changed the code of connect to this one:




client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.gmail.com", 587,
SecureSocketOptions.StartTlsWhenAvailable);




So it's clean that will use Tls when available. Certificate validation is turned off. It's working perfect in MailKit 2.0.7 but same code in 2.1.3 continue to throw the error in issue's description. Don't know why. May be have some bug in the all last versions(2.1.x)?






share|improve this answer

























  • As of MailKit 2.1.0, MailKit uses the SmtpClient.Timeout value to abort Connect after the timeout period has expired. By default, this timeout is 2 * 60 * 1000 - perhaps try setting it to a much larger value? Or try setting it to -1.

    – jstedfast
    Mar 28 at 12:00


















0















Part of the problem is that SMTP port 587 does not support SSL. You need to pass false as the useSsl argument.



Port 587 uses STARTTLS (which MailKit will automatically use if it can).



If you want more control, use the Connect[Async] methods that take a SecureSocketOptions enum value.



When using the Connect[Async] methods that take a boolean argument, true is the equivalent of SecureSocketOptions.SslOnCOnnect and false is the equivalent of SecureSOcketOptions.StartTlsWhenAvailable.



That said, however, the main part of the problem seems to be a bug in MailKit's newer Socket connection code. As of MailKit 2.1.x, MailKit began using Socket.BeginConnect (string host, int port, ...) instead of Socket.Connect (IPAddress address, int port) thereby allowing the underlying .NET implementation to resolve the host name into the appropriate IPAddress itself and to allow cancelability. Unfortunately, this seems to have broken things for some people (why?).



I have updated MailKit again to go back to resolving host names to a list of IP addresses (using Dns.GetHostAddresses[Async]) and looping over each IPAddress until it is able to successfully connect. This fix will be available in MailKit >= 2.1.4. Until then, you can install via the myget feed at https://www.myget.org/feed/mimekit/package/nuget/MailKit






share|improve this answer



























  • Actually I tried to set it to false but the error is the same. Tried with different SecureSocketOptions without success

    – GetTaxSolutions
    Mar 28 at 9:11











  • Can you write a simple program that uses a socket to connect to that host/port? Does it work? Maybe you have some sort of firewall in the way. The error suggests that the host rejected your connection.

    – jstedfast
    Mar 28 at 9:28











  • Tried with timeout -1. The same error. In the description of issue I was described that have 2 projects and start them on same machine - one use direct socket to connect to that host/port the other use MailKit. The first is working without any problems but Mailkt v.2.1.x not. Lower version of MailKit also are worked without changes in code. So the connectivity is fine.

    – GetTaxSolutions
    Mar 29 at 12:16












  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17












  • Did my fix work for you?

    – jstedfast
    Apr 2 at 10:26













Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382267%2fsend-mail-with-gmail-smtp-using-mailkit-smtp-client-in-net-core-2-2-is-not-work%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









1















I just partly-solved a very similar problem merely a few minutes ago; what I learned may help you.



In the case I have, there was reliably working code for MailKit to send from application with target of NET Core 2.1.



Recently I updated all the Nuget packages, thinking it was good practice to do this. Then I later discovered that my working SMTP send code had suddenly stopped working and it was reporting identical error to what you have experienced.



With this situation I checked all kinds of problems with smtp server, firewall, etc., until I remembered the Nuget update, began experimenting and eventually downgraded MailKit to 2.0.0. The send code began working again once MailKit had the version downgrade.



I have not pinpointed the exact location and mechanism of failure but have developed some confidence that (in the case I have been working on) the MailKit version used is directly involved. For today it's restored to working on the MailKit 2.0.0 downgrade and there is more research to be done to take it beyond that status.






share|improve this answer

























  • Try setting the client.Timeout to -1 to see if perhaps the problem is a connection timeout? That's the main thing that changed between 2.0 and 2.1 (Connect became cancellable via timeout value).

    – jstedfast
    Mar 28 at 15:03











  • Will check that out. The failure was consistent connecting against two entirely different smtp servers. (And success with both servers when heading back to 2.0.) There was no code change so maybe the default taken was not good.

    – An commercial developer
    Mar 28 at 16:59











  • Hmm, just remembered I changed from doing Dns.GetHostAddresses() and then looping over each IP address returned to just having Socket.Connect (string hostname, int port). Perhaps the problem is that Socket.Connect() when given a host name isn't using the right IP?

    – jstedfast
    Mar 28 at 19:13











  • Are you on a WIndows system or a Unix-based system like Linux/MacOS? Seems there is/was(?) a bug in .NET's SOcket logic when connecting via a hostname instead of an IPAddress because Linux/MacOS can't reuse sockets.

    – jstedfast
    Mar 29 at 10:32











  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17















1















I just partly-solved a very similar problem merely a few minutes ago; what I learned may help you.



In the case I have, there was reliably working code for MailKit to send from application with target of NET Core 2.1.



Recently I updated all the Nuget packages, thinking it was good practice to do this. Then I later discovered that my working SMTP send code had suddenly stopped working and it was reporting identical error to what you have experienced.



With this situation I checked all kinds of problems with smtp server, firewall, etc., until I remembered the Nuget update, began experimenting and eventually downgraded MailKit to 2.0.0. The send code began working again once MailKit had the version downgrade.



I have not pinpointed the exact location and mechanism of failure but have developed some confidence that (in the case I have been working on) the MailKit version used is directly involved. For today it's restored to working on the MailKit 2.0.0 downgrade and there is more research to be done to take it beyond that status.






share|improve this answer

























  • Try setting the client.Timeout to -1 to see if perhaps the problem is a connection timeout? That's the main thing that changed between 2.0 and 2.1 (Connect became cancellable via timeout value).

    – jstedfast
    Mar 28 at 15:03











  • Will check that out. The failure was consistent connecting against two entirely different smtp servers. (And success with both servers when heading back to 2.0.) There was no code change so maybe the default taken was not good.

    – An commercial developer
    Mar 28 at 16:59











  • Hmm, just remembered I changed from doing Dns.GetHostAddresses() and then looping over each IP address returned to just having Socket.Connect (string hostname, int port). Perhaps the problem is that Socket.Connect() when given a host name isn't using the right IP?

    – jstedfast
    Mar 28 at 19:13











  • Are you on a WIndows system or a Unix-based system like Linux/MacOS? Seems there is/was(?) a bug in .NET's SOcket logic when connecting via a hostname instead of an IPAddress because Linux/MacOS can't reuse sockets.

    – jstedfast
    Mar 29 at 10:32











  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17













1














1










1









I just partly-solved a very similar problem merely a few minutes ago; what I learned may help you.



In the case I have, there was reliably working code for MailKit to send from application with target of NET Core 2.1.



Recently I updated all the Nuget packages, thinking it was good practice to do this. Then I later discovered that my working SMTP send code had suddenly stopped working and it was reporting identical error to what you have experienced.



With this situation I checked all kinds of problems with smtp server, firewall, etc., until I remembered the Nuget update, began experimenting and eventually downgraded MailKit to 2.0.0. The send code began working again once MailKit had the version downgrade.



I have not pinpointed the exact location and mechanism of failure but have developed some confidence that (in the case I have been working on) the MailKit version used is directly involved. For today it's restored to working on the MailKit 2.0.0 downgrade and there is more research to be done to take it beyond that status.






share|improve this answer













I just partly-solved a very similar problem merely a few minutes ago; what I learned may help you.



In the case I have, there was reliably working code for MailKit to send from application with target of NET Core 2.1.



Recently I updated all the Nuget packages, thinking it was good practice to do this. Then I later discovered that my working SMTP send code had suddenly stopped working and it was reporting identical error to what you have experienced.



With this situation I checked all kinds of problems with smtp server, firewall, etc., until I remembered the Nuget update, began experimenting and eventually downgraded MailKit to 2.0.0. The send code began working again once MailKit had the version downgrade.



I have not pinpointed the exact location and mechanism of failure but have developed some confidence that (in the case I have been working on) the MailKit version used is directly involved. For today it's restored to working on the MailKit 2.0.0 downgrade and there is more research to be done to take it beyond that status.







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 27 at 21:22









An commercial developerAn commercial developer

111 bronze badge




111 bronze badge















  • Try setting the client.Timeout to -1 to see if perhaps the problem is a connection timeout? That's the main thing that changed between 2.0 and 2.1 (Connect became cancellable via timeout value).

    – jstedfast
    Mar 28 at 15:03











  • Will check that out. The failure was consistent connecting against two entirely different smtp servers. (And success with both servers when heading back to 2.0.) There was no code change so maybe the default taken was not good.

    – An commercial developer
    Mar 28 at 16:59











  • Hmm, just remembered I changed from doing Dns.GetHostAddresses() and then looping over each IP address returned to just having Socket.Connect (string hostname, int port). Perhaps the problem is that Socket.Connect() when given a host name isn't using the right IP?

    – jstedfast
    Mar 28 at 19:13











  • Are you on a WIndows system or a Unix-based system like Linux/MacOS? Seems there is/was(?) a bug in .NET's SOcket logic when connecting via a hostname instead of an IPAddress because Linux/MacOS can't reuse sockets.

    – jstedfast
    Mar 29 at 10:32











  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17

















  • Try setting the client.Timeout to -1 to see if perhaps the problem is a connection timeout? That's the main thing that changed between 2.0 and 2.1 (Connect became cancellable via timeout value).

    – jstedfast
    Mar 28 at 15:03











  • Will check that out. The failure was consistent connecting against two entirely different smtp servers. (And success with both servers when heading back to 2.0.) There was no code change so maybe the default taken was not good.

    – An commercial developer
    Mar 28 at 16:59











  • Hmm, just remembered I changed from doing Dns.GetHostAddresses() and then looping over each IP address returned to just having Socket.Connect (string hostname, int port). Perhaps the problem is that Socket.Connect() when given a host name isn't using the right IP?

    – jstedfast
    Mar 28 at 19:13











  • Are you on a WIndows system or a Unix-based system like Linux/MacOS? Seems there is/was(?) a bug in .NET's SOcket logic when connecting via a hostname instead of an IPAddress because Linux/MacOS can't reuse sockets.

    – jstedfast
    Mar 29 at 10:32











  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17
















Try setting the client.Timeout to -1 to see if perhaps the problem is a connection timeout? That's the main thing that changed between 2.0 and 2.1 (Connect became cancellable via timeout value).

– jstedfast
Mar 28 at 15:03





Try setting the client.Timeout to -1 to see if perhaps the problem is a connection timeout? That's the main thing that changed between 2.0 and 2.1 (Connect became cancellable via timeout value).

– jstedfast
Mar 28 at 15:03













Will check that out. The failure was consistent connecting against two entirely different smtp servers. (And success with both servers when heading back to 2.0.) There was no code change so maybe the default taken was not good.

– An commercial developer
Mar 28 at 16:59





Will check that out. The failure was consistent connecting against two entirely different smtp servers. (And success with both servers when heading back to 2.0.) There was no code change so maybe the default taken was not good.

– An commercial developer
Mar 28 at 16:59













Hmm, just remembered I changed from doing Dns.GetHostAddresses() and then looping over each IP address returned to just having Socket.Connect (string hostname, int port). Perhaps the problem is that Socket.Connect() when given a host name isn't using the right IP?

– jstedfast
Mar 28 at 19:13





Hmm, just remembered I changed from doing Dns.GetHostAddresses() and then looping over each IP address returned to just having Socket.Connect (string hostname, int port). Perhaps the problem is that Socket.Connect() when given a host name isn't using the right IP?

– jstedfast
Mar 28 at 19:13













Are you on a WIndows system or a Unix-based system like Linux/MacOS? Seems there is/was(?) a bug in .NET's SOcket logic when connecting via a hostname instead of an IPAddress because Linux/MacOS can't reuse sockets.

– jstedfast
Mar 29 at 10:32





Are you on a WIndows system or a Unix-based system like Linux/MacOS? Seems there is/was(?) a bug in .NET's SOcket logic when connecting via a hostname instead of an IPAddress because Linux/MacOS can't reuse sockets.

– jstedfast
Mar 29 at 10:32













Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

– jstedfast
Mar 29 at 12:17





Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

– jstedfast
Mar 29 at 12:17













0















I changed the code of connect to this one:




client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.gmail.com", 587,
SecureSocketOptions.StartTlsWhenAvailable);




So it's clean that will use Tls when available. Certificate validation is turned off. It's working perfect in MailKit 2.0.7 but same code in 2.1.3 continue to throw the error in issue's description. Don't know why. May be have some bug in the all last versions(2.1.x)?






share|improve this answer

























  • As of MailKit 2.1.0, MailKit uses the SmtpClient.Timeout value to abort Connect after the timeout period has expired. By default, this timeout is 2 * 60 * 1000 - perhaps try setting it to a much larger value? Or try setting it to -1.

    – jstedfast
    Mar 28 at 12:00















0















I changed the code of connect to this one:




client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.gmail.com", 587,
SecureSocketOptions.StartTlsWhenAvailable);




So it's clean that will use Tls when available. Certificate validation is turned off. It's working perfect in MailKit 2.0.7 but same code in 2.1.3 continue to throw the error in issue's description. Don't know why. May be have some bug in the all last versions(2.1.x)?






share|improve this answer

























  • As of MailKit 2.1.0, MailKit uses the SmtpClient.Timeout value to abort Connect after the timeout period has expired. By default, this timeout is 2 * 60 * 1000 - perhaps try setting it to a much larger value? Or try setting it to -1.

    – jstedfast
    Mar 28 at 12:00













0














0










0









I changed the code of connect to this one:




client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.gmail.com", 587,
SecureSocketOptions.StartTlsWhenAvailable);




So it's clean that will use Tls when available. Certificate validation is turned off. It's working perfect in MailKit 2.0.7 but same code in 2.1.3 continue to throw the error in issue's description. Don't know why. May be have some bug in the all last versions(2.1.x)?






share|improve this answer













I changed the code of connect to this one:




client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.gmail.com", 587,
SecureSocketOptions.StartTlsWhenAvailable);




So it's clean that will use Tls when available. Certificate validation is turned off. It's working perfect in MailKit 2.0.7 but same code in 2.1.3 continue to throw the error in issue's description. Don't know why. May be have some bug in the all last versions(2.1.x)?







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 28 at 9:37









GetTaxSolutionsGetTaxSolutions

64 bronze badges




64 bronze badges















  • As of MailKit 2.1.0, MailKit uses the SmtpClient.Timeout value to abort Connect after the timeout period has expired. By default, this timeout is 2 * 60 * 1000 - perhaps try setting it to a much larger value? Or try setting it to -1.

    – jstedfast
    Mar 28 at 12:00

















  • As of MailKit 2.1.0, MailKit uses the SmtpClient.Timeout value to abort Connect after the timeout period has expired. By default, this timeout is 2 * 60 * 1000 - perhaps try setting it to a much larger value? Or try setting it to -1.

    – jstedfast
    Mar 28 at 12:00
















As of MailKit 2.1.0, MailKit uses the SmtpClient.Timeout value to abort Connect after the timeout period has expired. By default, this timeout is 2 * 60 * 1000 - perhaps try setting it to a much larger value? Or try setting it to -1.

– jstedfast
Mar 28 at 12:00





As of MailKit 2.1.0, MailKit uses the SmtpClient.Timeout value to abort Connect after the timeout period has expired. By default, this timeout is 2 * 60 * 1000 - perhaps try setting it to a much larger value? Or try setting it to -1.

– jstedfast
Mar 28 at 12:00











0















Part of the problem is that SMTP port 587 does not support SSL. You need to pass false as the useSsl argument.



Port 587 uses STARTTLS (which MailKit will automatically use if it can).



If you want more control, use the Connect[Async] methods that take a SecureSocketOptions enum value.



When using the Connect[Async] methods that take a boolean argument, true is the equivalent of SecureSocketOptions.SslOnCOnnect and false is the equivalent of SecureSOcketOptions.StartTlsWhenAvailable.



That said, however, the main part of the problem seems to be a bug in MailKit's newer Socket connection code. As of MailKit 2.1.x, MailKit began using Socket.BeginConnect (string host, int port, ...) instead of Socket.Connect (IPAddress address, int port) thereby allowing the underlying .NET implementation to resolve the host name into the appropriate IPAddress itself and to allow cancelability. Unfortunately, this seems to have broken things for some people (why?).



I have updated MailKit again to go back to resolving host names to a list of IP addresses (using Dns.GetHostAddresses[Async]) and looping over each IPAddress until it is able to successfully connect. This fix will be available in MailKit >= 2.1.4. Until then, you can install via the myget feed at https://www.myget.org/feed/mimekit/package/nuget/MailKit






share|improve this answer



























  • Actually I tried to set it to false but the error is the same. Tried with different SecureSocketOptions without success

    – GetTaxSolutions
    Mar 28 at 9:11











  • Can you write a simple program that uses a socket to connect to that host/port? Does it work? Maybe you have some sort of firewall in the way. The error suggests that the host rejected your connection.

    – jstedfast
    Mar 28 at 9:28











  • Tried with timeout -1. The same error. In the description of issue I was described that have 2 projects and start them on same machine - one use direct socket to connect to that host/port the other use MailKit. The first is working without any problems but Mailkt v.2.1.x not. Lower version of MailKit also are worked without changes in code. So the connectivity is fine.

    – GetTaxSolutions
    Mar 29 at 12:16












  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17












  • Did my fix work for you?

    – jstedfast
    Apr 2 at 10:26















0















Part of the problem is that SMTP port 587 does not support SSL. You need to pass false as the useSsl argument.



Port 587 uses STARTTLS (which MailKit will automatically use if it can).



If you want more control, use the Connect[Async] methods that take a SecureSocketOptions enum value.



When using the Connect[Async] methods that take a boolean argument, true is the equivalent of SecureSocketOptions.SslOnCOnnect and false is the equivalent of SecureSOcketOptions.StartTlsWhenAvailable.



That said, however, the main part of the problem seems to be a bug in MailKit's newer Socket connection code. As of MailKit 2.1.x, MailKit began using Socket.BeginConnect (string host, int port, ...) instead of Socket.Connect (IPAddress address, int port) thereby allowing the underlying .NET implementation to resolve the host name into the appropriate IPAddress itself and to allow cancelability. Unfortunately, this seems to have broken things for some people (why?).



I have updated MailKit again to go back to resolving host names to a list of IP addresses (using Dns.GetHostAddresses[Async]) and looping over each IPAddress until it is able to successfully connect. This fix will be available in MailKit >= 2.1.4. Until then, you can install via the myget feed at https://www.myget.org/feed/mimekit/package/nuget/MailKit






share|improve this answer



























  • Actually I tried to set it to false but the error is the same. Tried with different SecureSocketOptions without success

    – GetTaxSolutions
    Mar 28 at 9:11











  • Can you write a simple program that uses a socket to connect to that host/port? Does it work? Maybe you have some sort of firewall in the way. The error suggests that the host rejected your connection.

    – jstedfast
    Mar 28 at 9:28











  • Tried with timeout -1. The same error. In the description of issue I was described that have 2 projects and start them on same machine - one use direct socket to connect to that host/port the other use MailKit. The first is working without any problems but Mailkt v.2.1.x not. Lower version of MailKit also are worked without changes in code. So the connectivity is fine.

    – GetTaxSolutions
    Mar 29 at 12:16












  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17












  • Did my fix work for you?

    – jstedfast
    Apr 2 at 10:26













0














0










0









Part of the problem is that SMTP port 587 does not support SSL. You need to pass false as the useSsl argument.



Port 587 uses STARTTLS (which MailKit will automatically use if it can).



If you want more control, use the Connect[Async] methods that take a SecureSocketOptions enum value.



When using the Connect[Async] methods that take a boolean argument, true is the equivalent of SecureSocketOptions.SslOnCOnnect and false is the equivalent of SecureSOcketOptions.StartTlsWhenAvailable.



That said, however, the main part of the problem seems to be a bug in MailKit's newer Socket connection code. As of MailKit 2.1.x, MailKit began using Socket.BeginConnect (string host, int port, ...) instead of Socket.Connect (IPAddress address, int port) thereby allowing the underlying .NET implementation to resolve the host name into the appropriate IPAddress itself and to allow cancelability. Unfortunately, this seems to have broken things for some people (why?).



I have updated MailKit again to go back to resolving host names to a list of IP addresses (using Dns.GetHostAddresses[Async]) and looping over each IPAddress until it is able to successfully connect. This fix will be available in MailKit >= 2.1.4. Until then, you can install via the myget feed at https://www.myget.org/feed/mimekit/package/nuget/MailKit






share|improve this answer















Part of the problem is that SMTP port 587 does not support SSL. You need to pass false as the useSsl argument.



Port 587 uses STARTTLS (which MailKit will automatically use if it can).



If you want more control, use the Connect[Async] methods that take a SecureSocketOptions enum value.



When using the Connect[Async] methods that take a boolean argument, true is the equivalent of SecureSocketOptions.SslOnCOnnect and false is the equivalent of SecureSOcketOptions.StartTlsWhenAvailable.



That said, however, the main part of the problem seems to be a bug in MailKit's newer Socket connection code. As of MailKit 2.1.x, MailKit began using Socket.BeginConnect (string host, int port, ...) instead of Socket.Connect (IPAddress address, int port) thereby allowing the underlying .NET implementation to resolve the host name into the appropriate IPAddress itself and to allow cancelability. Unfortunately, this seems to have broken things for some people (why?).



I have updated MailKit again to go back to resolving host names to a list of IP addresses (using Dns.GetHostAddresses[Async]) and looping over each IPAddress until it is able to successfully connect. This fix will be available in MailKit >= 2.1.4. Until then, you can install via the myget feed at https://www.myget.org/feed/mimekit/package/nuget/MailKit







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 30 at 20:09

























answered Mar 28 at 0:04









jstedfastjstedfast

20.9k3 gold badges58 silver badges81 bronze badges




20.9k3 gold badges58 silver badges81 bronze badges















  • Actually I tried to set it to false but the error is the same. Tried with different SecureSocketOptions without success

    – GetTaxSolutions
    Mar 28 at 9:11











  • Can you write a simple program that uses a socket to connect to that host/port? Does it work? Maybe you have some sort of firewall in the way. The error suggests that the host rejected your connection.

    – jstedfast
    Mar 28 at 9:28











  • Tried with timeout -1. The same error. In the description of issue I was described that have 2 projects and start them on same machine - one use direct socket to connect to that host/port the other use MailKit. The first is working without any problems but Mailkt v.2.1.x not. Lower version of MailKit also are worked without changes in code. So the connectivity is fine.

    – GetTaxSolutions
    Mar 29 at 12:16












  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17












  • Did my fix work for you?

    – jstedfast
    Apr 2 at 10:26

















  • Actually I tried to set it to false but the error is the same. Tried with different SecureSocketOptions without success

    – GetTaxSolutions
    Mar 28 at 9:11











  • Can you write a simple program that uses a socket to connect to that host/port? Does it work? Maybe you have some sort of firewall in the way. The error suggests that the host rejected your connection.

    – jstedfast
    Mar 28 at 9:28











  • Tried with timeout -1. The same error. In the description of issue I was described that have 2 projects and start them on same machine - one use direct socket to connect to that host/port the other use MailKit. The first is working without any problems but Mailkt v.2.1.x not. Lower version of MailKit also are worked without changes in code. So the connectivity is fine.

    – GetTaxSolutions
    Mar 29 at 12:16












  • Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

    – jstedfast
    Mar 29 at 12:17












  • Did my fix work for you?

    – jstedfast
    Apr 2 at 10:26
















Actually I tried to set it to false but the error is the same. Tried with different SecureSocketOptions without success

– GetTaxSolutions
Mar 28 at 9:11





Actually I tried to set it to false but the error is the same. Tried with different SecureSocketOptions without success

– GetTaxSolutions
Mar 28 at 9:11













Can you write a simple program that uses a socket to connect to that host/port? Does it work? Maybe you have some sort of firewall in the way. The error suggests that the host rejected your connection.

– jstedfast
Mar 28 at 9:28





Can you write a simple program that uses a socket to connect to that host/port? Does it work? Maybe you have some sort of firewall in the way. The error suggests that the host rejected your connection.

– jstedfast
Mar 28 at 9:28













Tried with timeout -1. The same error. In the description of issue I was described that have 2 projects and start them on same machine - one use direct socket to connect to that host/port the other use MailKit. The first is working without any problems but Mailkt v.2.1.x not. Lower version of MailKit also are worked without changes in code. So the connectivity is fine.

– GetTaxSolutions
Mar 29 at 12:16






Tried with timeout -1. The same error. In the description of issue I was described that have 2 projects and start them on same machine - one use direct socket to connect to that host/port the other use MailKit. The first is working without any problems but Mailkt v.2.1.x not. Lower version of MailKit also are worked without changes in code. So the connectivity is fine.

– GetTaxSolutions
Mar 29 at 12:16














Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

– jstedfast
Mar 29 at 12:17






Try going to myget.org/feed/mimekit/package/nuget/MailKit and installing the latest MailKit version (>= 2.1.3.15). I made some changes to the Connect logic that may solve this?

– jstedfast
Mar 29 at 12:17














Did my fix work for you?

– jstedfast
Apr 2 at 10:26





Did my fix work for you?

– jstedfast
Apr 2 at 10:26

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55382267%2fsend-mail-with-gmail-smtp-using-mailkit-smtp-client-in-net-core-2-2-is-not-work%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

위키백과:대문 둘러보기 메뉴기부 안내모바일판 대문크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0CebuanoDeutschEnglishEspañolFrançaisItaliano日本語NederlandsPolskiPortuguêsРусскийSvenskaTiếng ViệtWinaray中文العربيةCatalàفارسیSrpskiУкраїнськаБългарскиНохчийнČeštinaDanskEsperantoEuskaraSuomiעבריתMagyarՀայերենBahasa IndonesiaҚазақшаBaso MinangkabauBahasa MelayuBân-lâm-gúNorskRomânăSrpskohrvatskiSlovenčinaTürkçe

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh