Click here to Skip to main content
15,886,761 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to get data(like email) from database and use this data to send email

What I have tried:

context.AddParameter("@Username", model.UserName);
context.AddParameter("@Password", model.Password);
DataTable dtgetemail = context.getData("getemailforcoderesend", CommandType.StoredProcedure);
if (dtgetemail.Rows.Count == 1)
{
 context.AddParameter("@Username", model.UserName);
 context.AddParameter("@Password", model.Password);
 DataTable dtgetemailcode = context.getData("getemailverificationcode", CommandType.StoredProcedure);       //code edit on 29/10/2020


 if (dtgetemailcode.Rows.Count == 1)
 {
     //WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
     //WebSecurity.Login(model.UserName, model.Password);

     MailMessage msg = new MailMessage();
     SmtpClient smtp = new SmtpClient();
     MailAddress from = new MailAddress("info@service.com");
     StringBuilder sb = new StringBuilder();
     msg.IsBodyHtml = true;
     smtp.Host = "smtp.zoho.com";
     smtp.Port = 587;

     msg.To.Add(dtgetemailcode.ToString());  //Error is here..

     msg.From = from;
     msg.Subject = "Registration success full on abc! ";
     msg.Body += "<html>";
     msg.Body += "<body>";
     msg.Body += "<table>";
     msg.Body += "<tr>";
     msg.Body += "<td>Thank you for registering on VibExChange. Please verify your email. </td>";
     //msg.Body += "<td>Thank you for registering on VibExChange. Your User Name and Password is : </td>";
     msg.Body += "</tr>";
     msg.Body += "<tr>";
     msg.Body += "<td>User Name : </td><td>" + model.UserName + "</td>";
     msg.Body += "</tr>";
     msg.Body += "<tr>";
     // msg.Body += "<td>Password : </td><td>" + model.Password + "</td>";
     msg.Body += "</tr>";
     msg.Body += "<tr>";
     msg.Body += "<td>Email Pin : </td><td>" + dtgetemailcode.ToString() + "</td>";   //Error is here..
     msg.Body += "</tr>";
     msg.Body += "<tr>";
     msg.Body += "<td>for Email Verification </td><td><a href='http://www.abc.com/Home/EmailVerification'> Click Here </a></td>";
     msg.Body += "</tr>";
     msg.Body += "<td>for more information </td><td><a href='http://www.abc.com/'> Click Here </a></td>";
     msg.Body += "</tr>";
     msg.Body += "</table>";
     msg.Body += "</body>";
     msg.Body += "</html>";
     smtp.UseDefaultCredentials = false;
     smtp.EnableSsl = true;
     smtp.Credentials = new System.Net.NetworkCredential("info@service.com", "ishant@78");
     smtp.Send(msg);
     msg.Dispose();
     Session.Abandon();
     Session.Clear();
     Session.RemoveAll();
     return Content("<script language='javascript' type='text/javascript'>alert('Email is not verified!!!'); window.location.href ='http://www.abc.com/Home/EmailVerification';</script>");
     //return RedirectToAction("EditUserProfile", "Home");
     //return RedirectToAction("EmailVerification", "Home");
 }
Posted
Updated 29-Oct-20 0:17am
Comments
OriginalGriff 29-Oct-20 5:30am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with. Come on, you've asked more than enough questions to know that you need to give us actual information!

Use the "Improve question" widget to edit your question and provide better information.
Member 14743579 29-Oct-20 6:21am    
Actually i am trying to get the user's email id from database when user try to login their on account. After that i sent the mail to the user.
finally i got the solution using session.
Richard Deeming 29-Oct-20 6:13am    
Looks like you're storing passwords in plain text. Don't do that.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

1 solution

Quote:
C#
DataTable dtgetemailcode = ...;
...
msg.To.Add(dtgetemailcode.ToString());
The variable dtgetemailcode is a DataTable. Calling .ToString() on that variable will return it's TableName. This will either be an empty string, or something like Table1. That is clearly NOT a valid email address.

You need to use the value of the correct column of the correct row of the DataTable instead.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900