.NET provides a nice, elegant way to define SMTP configuration in an application configuration file:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="somewhere@example.com">
<network host="mySmtpServer" ...more authentication data... />
</smtp>
</mailSettings>
</system.net>
SmtpClient uses this configuration automatically, and, heck, I can even access these setting programmatically, if I need to:
var mailSettings = (MailSettingsSectionGroup)myAppConfig.GetSectionGroup("system.net/mailSettings");
// now I can access mailSettings.Smtp.Network.Host, etc.
And now to something completely different:
It happens that I have an external XML configuration file (not app.config or web.config), and I need to store SMTP configuration data there, so I thought I'd just use the same format that .NET uses. After all, some very smart people put a lot of thought into that, so why reinvent the wheel?
Now, finally (thanks for your patience), we get to the question:
Can I reuse the MailSettingsSectionGroup parser?
I was hoping that there is some public MailSettingsSectionGroup.Parse(myXElement)
method or some new MailSettingsSectionGroup(myXElement)
constructor, but I could not find one. Is the parser publicly available or is it hidden in some internal System.Configuration
class that I cannot reuse?