Home Dashboard Directory Help
Search

SmtpClient reports InvalidOperationException when disposed immediatelly after sending mail and pickup directory is used by Michal Altair Valasek


Status: 

Closed
 as Fixed Help for as Fixed


13
0
Sign in
to vote
Type: Bug
ID: 539160
Opened: 3/4/2010 12:49:30 PM
Access Restriction: Public
1
Workaround(s)
view
9
User(s) can reproduce this bug

Description

Since 4.0, System.Net.Mail.SmtpClient class is IDisposable. However, when disposed immediatelly after the Send method is called, InvalidOperationException "The SMTP host was not specified. " is thrown, even though DeliveryMethod property is set to SpecifiedPickupDirectory and there is no need to set SMTP server.

Tested in context of web application.
Details
Sign in to post a comment.
Posted by Microsoft on 12/5/2011 at 11:11 AM
The fix is available in the .NET 4.5 Developer Preview found here:
http://msdn.microsoft.com/en-us/netframework/hh403373
Posted by Gerard van der Land on 11/28/2011 at 1:14 AM
This bug is closed as fixed but there is no mention in the comment how to obtain this fix. On a fully patched system I'm still experiencing this bug.
Posted by Raymondr on 12/29/2010 at 12:36 AM
The solution provided by Tratcher shouldn't be used.
In this way the smtp settings are hard coded. It's better to provide the settings in a config file. The delivery method can than be choosen at time of deployment. During development you might want to use the pickup directory, and in production you might want to use a SMTP server. If you hardcode "anything" this wil always overrule the config setting, so you can't use a SMTP server any more by changing the config
The complete config setting would be

     <smtp from="user@domain.com" deliveryMethod="SpecifiedPickupDirectory">
        <network host="localhost" />
        <specifiedPickupDirectory pickupDirectoryLocation="c:\temp\mail" />
     </smtp>
Posted by pagebrooks on 12/21/2010 at 5:00 AM
I just got burned by this issue. Thanks for posting a workaround!
Posted by Nicholas Piasecki on 7/1/2010 at 7:43 AM
andrewdavey's workaround works for me.

This is a pretty careless defect.
Posted by Tratcher on 5/31/2010 at 7:49 AM
The following should work:

using (SmtpClient client = new SmtpClient("anything"))
{
// Send to pickup directory
...
}
Posted by PeterRow on 5/31/2010 at 6:27 AM
The workaround specified by andrewdavey on 08/04/2010 doesn't work for me and I still get the error.
Posted by Microsoft on 3/8/2010 at 4:44 PM
Thank you for reporting this issue. I have confirmed that this is a bug, however it will not be fixed by 4.0 RTM. We will investigate the issue for a future release.

Please let us know if you need additional help with workarounds for this issue.
Posted by Microsoft on 3/4/2010 at 7:24 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.

Thank you
Posted by Microsoft on 3/4/2010 at 7:05 PM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
Posted by Andrew Davey on 4/8/2010 at 5:41 AM
Add the network element after the specifiedPickupDirectory element:
<network host="localhost"/>

P.S. Microsoft - not fixing this for RTM is lame :(