Creating SMTP in Web Config File
<configuration>
<system.net>
<mailSettings >
<smtp>
<network host=”smtp.gmail.com” port=”587″ userName=”Email Id” password=”Password” />
</smtp>
</mailSettings>
</system.net>
<appSettings>
<add key=”MailFrom” value=”Email Id”/>
</appSettings>
</configuration>
//Call this Function From where u want to sen Email using App Settings in Config File
public bool SendEmail(string name, string email, string sub,string msg1,string phone )
{
SmtpClient sm = new SmtpClient();
MailMessage msg = new MailMessage();
string msgfromadd = ConfigurationManager.AppSettings[“MailFrom”];
MailAddress frmadd = new MailAddress(msgfromadd);
msg.BodyEncoding = System.Text.Encoding.UTF8;
msg.From = frmadd;
msg.To.Add(email);
msg.Subject = name + ” ” + sub + ” ” + phone;
msg.Body = msg1;
msg.IsBodyHtml = true;
sm.EnableSsl = true;
try
{
sm.Send(msg);
return true;
}
catch
{
return false;
}
}