Saving the smtp details in web.config file like this:
<system.net>
<mailSettings>
<smtp from="username@gmail.com">
<network host="smtp.gmail.com" port="587" userName="username@gmail.com" password="password" defaultCredentials="true"/>
</smtp>
</mailSettings>
</system.net>
and retrieving the smtp detail in cs file follow like this:  
SmtpSection MailSettings = (SmtpSection)ConfigurationManager.GetSection("system.net/mailSettings/smtp");
 if (MailSettings != null)
 {
    string From = MailSettings.From;
    int Port = MailSettings.Network.Port;
    string Host = MailSettings.Network.Host;
    string Password = MailSettings.Network.Password;
    string UserName = MailSettings.Network.UserName;
}
Tags: Smtp server details from web.config file, gmail smtp settings in web.config file
 
 
 
 
No comments:
Post a Comment