Accedere alla configurazione del server SMTP del file WEB.CONFIG
Ecco un esempio d configurazione del file web.config nella sezione <configuration>:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from=mail@ferdinandocaprilli.it>
<network defaultCredentials="true" host="localhost" port="25" userName="provaUsername" password="provaPassword"/>
</smtp>
</mailSettings>
</system.net>
Poi occorre aggiungere i seguenti namespaces nella nostra pagina:
using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration;
Successivamente si possono richiamare in questo modo:
Configuration config = WebConfigurationManager.OpenWebConfiguration(HttpContext.Current.Request.ApplicationPath);
MailSettingsSectionGroup settings = (MailSettingsSectionGroup)config.GetSectionGroup("system.net/mailSettings");
string host= settings.Smtp.Network.Host ;
string port=settings.Smtp.Network.Port;
string Username=settings.Smtp.Network.UserName;
string Password=settings.Smtp.Network.Password ;
string from=settings.Smtp.From;