how to send a confirmation mail after registration in asp.net.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Praveen DhatrikaPosted Jan 27, 2016, 4:07 PM
- protected void SendEmail(object sender, EventArgs e)
-
- {
- //calling for creating the email body with html template
-
- string body = this.createEmailBody(txt_name.Text, "Please check your account Information", txt_message.Text);
-
- this.SendHtmlFormattedEmail("New article published!", body);
-
- }
-
- private string createEmailBody(string userName, string title, string message)
-
- {
-
- string body = string.Empty;
- //using streamreader for reading my htmltemplate
-
- using(StreamReader reader = new StreamReader(Server.MapPath("~/HtmlTemplate.html")))
-
- {
-
- body = reader.ReadToEnd();
-
- }
-
- body = body.Replace("{UserName}", userName); //replacing the required things
-
- body = body.Replace("{Title}", title);
-
- body = body.Replace("{message}", message);
-
- return body;
-
- }
-
- private void SendHtmlFormattedEmail(string subject, string body)
-
- {
-
- using(MailMessage mailMessage = new MailMessage())
-
- {
-
- mailMessage.From = new MailAddress(ConfigurationManager.AppSettings["UserName"]);
-
- mailMessage.Subject = subject;
-
- mailMessage.Body = body;
-
- mailMessage.IsBodyHtml = true;
-
- mailMessage.To.Add(new MailAddress(txt_email.Text));
-
- SmtpClient smtp = new SmtpClient();
-
- smtp.Host = ConfigurationManager.AppSettings["Host"];
-
- smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
-
- System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
-
- NetworkCred.UserName = ConfigurationManager.AppSettings["UserName"]; //reading from web.config
-
- NetworkCred.Password = ConfigurationManager.AppSettings["Password"]; //reading from web.config
-
- smtp.UseDefaultCredentials = true;
-
- smtp.Credentials = NetworkCred;
-
- smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]); //reading from web.config
-
- smtp.Send(mailMessage);
-
- }
-
- }
please go through this ..If you find this helpful, please accept this as answer :)