tags:

views:

610

answers:

4

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.

See http://www.vbforums.com/showthread.php?p=3609268 for more details.

+10  A: 

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.

lethek
Thanks for the info - I'll look into it.
Mike C.
Just make sure, that you adhere to Mono license ( http://www.mono-project.com/Licensing ). The source code is under MIT X11 license, which basically means that you have to tell somewhere in the documentation that you are using part of mono and you also have to cite the license text in your documentation.
Martin Vobr
@lethek - how would you go about doing this?
JL
lethek
@Lethek, any chance of you making that mono modified DLL public?
JL
+4  A: 

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.

mookid8000
We are required to use SMTP on a different server.
Mike C.
The SMTP service is a relay agent only - mails are forwarded to an SMTP server of your choice.
mookid8000
This means you have to configure and maintain the local SMTP server right?
JL
+2  A: 

It is solved in .Net 4. They implemented IDispose and this sends the QUIT command and frees resources.

This is a copy of the relevant documentation on MSDN:

The SmtpClient class has no Finalize method, so an application must call Dispose to explicitly free up resources. The Dispose method iterates through all established connections to the SMTP server specified in the Host property and sends a QUIT message followed by gracefully ending the TCP connection. The Dispose method also releases the unmanaged resources used by the Socket and optionally disposes of the managed resources.

Call Dispose when you are finished using the SmtpClient. The Dispose method leaves the SmtpClient in an unusable state. After calling Dispose, you must release all references to the SmtpClient so the garbage collector can reclaim the memory that the SmtpClient was occupying.

Bas Jansen
-1 The SMTPClient in .net v4.0 RTM is unable to send attachments larger than 3-4MB's so using .net v4.0 RTM for mailing is not a solution!
JL
It is a known bug and it will be fixed in the future. See: http://connect.microsoft.com/VisualStudio/feedback/details/544562/cannot-send-e-mails-with-large-attachments-system-net-mail-smtpclient-system-net-mail-mailmessage
Bas Jansen
A public patch is now available for this issue. You can find it here:https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=30226
Bas Jansen
A: 

Looks like I'm going to find a 3rd party product to fix the problem. The mono solution sounds interesting, but I'd rather spend a few bucks and get a commercial solution.

Mike C.
This should be a comment, not an answer
Josh Stodola
No, it's the answer as to how I'm going to get around the limitation.
Mike C.