SmtpClient throws InvalidOperationException when using SpecifiedPickupDirectory
I was asked today to amend the settings for a bulk email application I’ve recently written - using the
Pretty simple change I though - amend the deliveryMethod to SpecifiedPickupDirectory and provide a <specifiedPickupDirectory/> element with the path to the pickup directory that had already been configured:
However causes an exception to be thrown. After some head scratching and a bit of Googling, it appears that this is a bug in the .NET 4.0 framework. When the SMTP Client object is defined in a using block
you must define the <network/> attribute after the <specifiedPickupDirectory/>, even though you don’t want to use it: