public void MailSant(string
Subject, string message_text, string to1)
{
//------------
Mail Code Start here ....
MailMessage
mailmessage = new MailMessage("ajayrajpoot1993@gmail.com", to1);
mailmessage.Subject = Subject;
mailmessage.Body = message_text;
SmtpClient
smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.UseDefaultCredentials = true;
smtp.Credentials = new NetworkCredential()
{
UserName = "ajayrajpoot1993@gmail.com",
Password = "*********"
};
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
//
mailmessage.IsBodyHtml = true;
smtp.Send(mailmessage);
}
//==============One More code Sand with HTML Tages
protected void btnSubmit_Click(object sender, EventArgs e)
{
using (MailMessage mm = new MailMessage(ConfigurationManager.AppSettings["SMTPuser"], txtEmail.Text))
{
mm.Subject = "Employee Information Detail";
mm.Body = CreateBody();
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["Host"];
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(ConfigurationManager.AppSettings["SMTPuser"], ConfigurationManager.AppSettings["SMTPpassword"]);
smtp.UseDefaultCredentials = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]);
smtp.Credentials = NetworkCred;
smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
smtp.Send(mm);
Response.Write("alert('Email Sent..');");
}
}
private string CreateBody()
{
string body = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTamplate.html")))
{
body = reader.ReadToEnd();
}
body = body.Replace("{fname}", txtfname.Text); //replacing Parameters
body = body.Replace("{lname}", txtlname.Text);
body = body.Replace("{dob}", txtdob.Text);
body = body.Replace("{post}", txtpost.Text);
body = body.Replace("{designation}", txtdesignation.Text);
return body;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
using (MailMessage mm = new MailMessage(ConfigurationManager.AppSettings["SMTPuser"], txtEmail.Text))
{
mm.Subject = "Employee Information Detail";
mm.Body = CreateBody();
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = ConfigurationManager.AppSettings["Host"];
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential(ConfigurationManager.AppSettings["SMTPuser"], ConfigurationManager.AppSettings["SMTPpassword"]);
smtp.UseDefaultCredentials = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSSL"]);
smtp.Credentials = NetworkCred;
smtp.Port = int.Parse(ConfigurationManager.AppSettings["Port"]);
smtp.Send(mm);
Response.Write("alert('Email Sent..');");
}
}
private string CreateBody()
{
string body = string.Empty;
using (StreamReader reader = new StreamReader(Server.MapPath("~/EmailTamplate.html")))
{
body = reader.ReadToEnd();
}
body = body.Replace("{fname}", txtfname.Text); //replacing Parameters
body = body.Replace("{lname}", txtlname.Text);
body = body.Replace("{dob}", txtdob.Text);
body = body.Replace("{post}", txtpost.Text);
body = body.Replace("{designation}", txtdesignation.Text);
return body;
}
No comments:
Post a Comment