SMTP Authentication with config file's MailSettings
I'm storing my MailSettings in a web.config, however when I send the message, my SMTP server reports back that I need to use authentication. I've got my username/password in the config file, but it still fails.
It works if I do the following, but it seems like an extra step. Shouldn't it just take it from the config file and use authentication automatically?
System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration( HttpContext.Current.Request.ApplicationPath); MailSettingsSectionGroup settings = (MailSettingsSectionGroup) config.GetSectionGroup("system.net/mailSettings"); SmtpClient client = new SmtpClient(); client.Credentials = new NetworkCredential( settings.Smtp.Network.UserName, settings.Smtp.Network.Password);
<system.net> <mailSettings> <smtp from="firstname.lastname@example.org" deliveryMethod="Network"> <network host="mail.xyz.com" defaultCredentials="true" userName="me@xyzcom" password="abc123" /> </smtp> </mailSettings> </system.net>
Exceeded storage allocation. The server response was: Please use smtp authentication.
The "Exceeded storage allocation" confused us for quite awhile, we now ignore it. It's the "use smtp authentication" that seems to be important.