1. using namespaces like that :
using System.Net.Mail;
using System.Net;
2. write code for sending mail and get SMTP server info from web.config:
MailMessage msgObj = new MailMessage();
MailAddress addFrom = new MailAddress(strForm);msgObj.From = addFrom;msgObj.To.Add(strTo);msgObj.Priority = MailPriority.High;
msgObj.Subject = strSubject;msgObj.Body = strBody;msgObj.IsBodyHtml = false;
SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings.Get("smtpserver");
smtp.Port = Convert.ToInt32(ConfigurationManager.AppSettings.Get("port"));
string Uname = ConfigurationManager.AppSettings.Get("uname");
string password = ConfigurationManager.AppSettings.Get("pass");
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;smtp.Timeout = 120000;
smtp.EnableSsl = true; // true gor gmail, false for non-SSL
smtp.Credentials = new NetworkCredential(Uname, password);
try
{
smtp.Send(msgObj);
}
catch (Exception ex){throw ex;}
3. write code in web.config inside appsetting tag.
appsettings
add value="smtpservername" key="smtpserver"
add value="25" key="port" !-- port 25 is default, 465 0r 587 for gmail .
add value="username" key="uname">
add value="password" key="pass"
/appsettings
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment