Hi,
Please check this.
Sending low product quantity details in a single mail
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
SqlCommand sqlCommand = new SqlCommand("select Id from products where quantity<5", con);
int var = 0;
string pro = "You product with low quantity are :";
con.Open();
using (SqlDataReader read = sqlCommand.ExecuteReader())
{
while (read.Read())
{
string Id1;
Id1 = read["Id"].ToString();
pro += Convert.ToString(Id1)+", ";
}
pro = pro.Substring(0,pro.Length - 2);
MailMessage mailObj = new MailMessage(
"from", "to", "product low quantity",pro);
SmtpClient SMTPServer = new SmtpClient("localhost");
try
{
SMTPServer.UseDefaultCredentials = false;
SMTPServer.Host = "smtp.gmail.com";
SMTPServer.Port = 587;
SMTPServer.Credentials = new NetworkCredential("email", "password");
SMTPServer.EnableSsl = true;
SMTPServer.Send(mailObj);
}
catch (Exception ex)
{
}
read.Close();
con.Close();
}
}
}