Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET System.Net.Mail.SmtpClient class doesn't issue QUIT command to SMTP transaction

Tags:

.net

smtp

Has anybody had issues with this? If so, how do you get around it? We are getting sporadic timeout issues and this is getting blamed.

The same issue is reported here as well:

http://www.vbforums.com/showthread.php?p=3609268

like image 479
Mike Cole Avatar asked Dec 03 '22 07:12

Mike Cole


2 Answers

I don't know if there's an easier way to work around this specific problem, but one option would be to download the source for Mono's SmtpClient and use that (modifying if necessary). Their version definitely does send a QUIT command.

One project that I work on required us to send large numbers of emails. .NET's implementation was too inefficient, not providing any way to send multiple distinct emails in the same SMTP session. We fell back on using Mono's implementation and modifying it to allow us to manually control when the QUIT command was sent and the connection closed. There were a total of 25 relevant Mono classes that we had to merge into our project for this (mostly copy+paste and edit namespace).

It seems a little extreme, but if there's no way to work around the issue, it may be your best 3rd-party alternative: it's free, it's not a great deal of work and its API is almost identical to the native SmtpClient's.

like image 188
lethek Avatar answered Dec 26 '22 06:12

lethek


Is your application running on a machine with an IIS? If so, you could take advantage of the built-in SMTP Service by setting the delivery method of your SMTP client like this:

var client = new SmtpClient 
{ 
    DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis 
};

I am using this in a few applications, and it's very reliable.

like image 21
mookid8000 Avatar answered Dec 26 '22 06:12

mookid8000