Jaya Prakash

Jaya Prakash

  • 546
  • 2.3k
  • 64.8k

SqlServer system.net.mailmessage

Feb 23 2023 8:45 AM

This is my Otp generation code I need to save msg.body into data base pls help me out.. 

string newPwd = GenerateOtp().ToString();
Session["session1"] = newPwd;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]");
msg.To.Add(TextBox1.Text);
string name = newtxtbx.Text;
msg.Subject = "Pls Verify Below Otp";
msg.Body = "Hi Dear!" + "\n" + name + "\n" + " Your Otp is " + "\n " + newPwd + " " + "Generated and Sent By" + "\n" + "K.J.S.P";
msg.IsBodyHtml = true;

SmtpClient smt = new SmtpClient();
smt.Host = "smtp.gmail.com";
System.Net.NetworkCredential ntwd = new NetworkCredential();
ntwd.UserName = "[email protected]";
ntwd.Password = "tmfegdxjspdadyyt";
smt.UseDefaultCredentials = true;
smt.Credentials = ntwd;
smt.Port = 587;
smt.EnableSsl = true;
smt.Send(msg);
//lblMessage.Text = "Email Sent Successfully";
Response.Write("<script>alert('Email Sent Successfully')</script>");
Session["msg"] = msg;
//lblMessage.ForeColor = System.Drawing.Color.ForestGreen;
Button2.Text = "Email";

This my code to save into database once i received otp to my mail i am able to save otp but when  i want to save message into db showing   "SqlServer system.net.mailmessage " this error pls help me out with this

ScriptManager.RegisterStartupScript(this, typeof(string), "Message", "confirm('Your Email  Has Been Verified Successfully.');", true);
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ToString());
SqlCommand cmd = new SqlCommand("sp_SaveOtpDetails", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", newtxtbx.Text);
cmd.Parameters.AddWithValue("@email", TextBox1.Text);
cmd.Parameters.AddWithValue("@otps", Session["session1"]);
cmd.Parameters.AddWithValue("@msg", Session["msg"]);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();

 


Answers (4)