Harun

Harun

  • 2k
  • 5
  • 124

Sending Mail With Asp.Net WebForm

Feb 23 2021 11:28 AM
Hi,
I send e-mails with the method I prepared. In the content of this e-mail, there is an html table containing the records responsible for the persons to be sent. However, at the moment, the mail is not sent in a private way. In other words, the mail sent to the people sends not only the records of the relevant person, but also the records of other people. However, for example, I want only data related to the records that he is responsible for to be sent to the person named x. I think for that, I need to check that the next record does not belong to the person concerned and exit the loop if the condition is valid. And then I have to loop again and continue from the next user. But somehow I could not achieve the result I wanted. I ask for your help.
  1. private void SendMailIfNoComment()      
  2. {      
  3.     using (SqlConnection conn = new SqlConnection(myDbConnect))      
  4.     {      
  5.         using (SqlCommand cmd = new SqlCommand("sp_CheckIfaCommentHasBeenMade", conn))      
  6.         {      
  7.             cmd.CommandType = CommandType.StoredProcedure;      
  8.             int mailsayac = 0;      
  9.             DataSet ds = new DataSet();      
  10.             SqlDataAdapter adp = new SqlDataAdapter();      
  11.             adp.SelectCommand = cmd;      
  12.             adp.Fill(ds);      
  13.             string MailSubject = string.Empty, danismanMail = string.Empty, MailBody = string.Empty, IstekTarihi = string.Empty, MailFrom = "xxx";      
  14.             int i;      
  15.             if (ds.Tables[0].Rows.Count > 0)      
  16.             {      
  17.                 MailSubject = "xxx";      
  18.                 MailBody = "<table style=\"border:0px;width:900px;font-family:Arial;font-size:12px;\"><tr>";      
  19.                 MailBody += "<td valign=\"top\" style=\"font-weight:bold;width:100px;border:1px solid navy\">Istek No</td>";      
  20.                 MailBody += "<td valign=\"top\" style=\"font-weight:bold;width:400px;border:1px solid navy\">Istek</td>";      
  21.                 MailBody += "<td valign=\"top\" style=\"font-weight:bold;width:100px;border:1px solid navy\">Sorumlu Danisman</td>";      
  22.                 MailBody += "<td valign=\"top\" style=\"font-weight:bold;width:100px;border:1px solid navy\">Istek Sorumlusu</td>";      
  23.                 MailBody += "<td valign=\"top\" style=\"font-weight:bold;width:100px;border:1px solid navy\">Istek Durumu</td>";      
  24.                 MailBody += "<td valign=\"top\" style=\"font-weight:bold;width:100px;border:1px solid navy\">Istek Tarihi</td>";      
  25.                 MailBody += "";      
  26.                 mailsayac = 0;  
  27.                 foreach (DataRow row in ds.Tables[0].Rows)      
  28.                 {      
  29.                     danismanMail = row["DanismanMail"].ToString();      
  30.                     IstekTarihi = string.IsNullOrEmpty(row["istek_tarihi"].ToString()) == false ? string.Format("{0:dd.MM.yyyy}", row["istek_tarihi"]) : string.Empty;      
  31.                     MailBody += "<tr><td valign=\"top\" style=\"width:100px;border:1px solid navy\"><href="" + row["IstekNo"].ToString() + "\">" + row["IstekNo"].ToString() + "</a></td>";      
  32.                     MailBody += "<td valign=\"top\" style=\"width:400px;border:1px solid navy\">" + row["istek"].ToString() + "</td>";      
  33.                     MailBody += "<td valign=\"top\" style=\"width:100px;border:1px solid navy\">" + row["Danisman"].ToString() + "</td>";      
  34.                     MailBody += "<td valign=\"top\" style=\"width:100px;border:1px solid navy\">" + row["IstekSorumlusu"].ToString() + "</td>";      
  35.                     MailBody += "<td valign=\"top\" style=\"width:100px;border:1px solid navy\">" + row["durum"].ToString() + "</td>";      
  36.                     MailBody += "<td valign=\"top\" style=\"width:100px;border:1px solid navy\">" + IstekTarihi + "</td>";      
  37.                     mailsayac++;                          
  38.                 }      
  39.                 MailBody += "</table>";  
  40.                 if (mailsayac > 0) MailUtils.SendMail(MailSubject, MailFrom, danismanMail.Split(';'), "smtp.yandex.com.tr", MailBody, true, Session["UserEmail"].ToString());  
  41.             }      
  42.         }      
  43.     }  
  44. } 

Answers (2)