This is my web.config
mail settings:
By using the configuration, the following line:
var smtp = new System.Net.Mail.SmtpClient();
Will use the configured values - you don't need to access and assign them again.
As for the null
values - you are trying accessing the configuration values incorrectly. You are just creating an empty SmtpSection
instead of reading it from configuration.
var smtpSection = (SmtpSection)ConfigurationManager.GetSection("");
var credentials == smtpSection.Network;