public void SendMails() { MailMessage msgMail = new MailMessage(); string str = "select * from temp"; // fetching the data from "temp" file regarding emails SqlDataAdapter sda = new SqlDataAdapter(str, cn); DataTable dt = new DataTable(); sda.Fill(dt); string str2 = "select * from tdocument where STAT='APPROVED' and doc_id='" + Id + "'"; // fetching the data for Approved document SqlDataAdapter sda2 = new SqlDataAdapter(str, cn); DataSet ds2 = new DataSet(); sda.Fill(ds2); string dc = ds2.Tables[0].Rows[0].ItemArray[0].ToString(); // storing the data here regarding the approved document for the mail format string AutName = ds2.Tables[0].Rows[0].ItemArray[1].ToString(); string FilName = ds2.Tables[0].Rows[0].ItemArray[4].ToString(); string doc_id = ds2.Tables[0].Rows[0].ItemArray[6].ToString(); string Stat = ds2.Tables[0].Rows[0].ItemArray[7].ToString(); string UpldDate = ds2.Tables[0].Rows[0].ItemArray[9].ToString(); string str1 = "select email from temp where emp_code='" + ApprovrId + "'"; // fetching the "email id" of the person who has logged in string mid, nm; SqlDataAdapter sda1 = new SqlDataAdapter(str, cn); DataSet ds = new DataSet(); sda.Fill(ds); mid = ds.Tables[0].Rows[0].ItemArray[6].ToString(); // for email id nm = ds.Tables[0].Rows[0].ItemArray[1].ToString(); // for name of emp for (int i = 0; i < dt.Rows.Count; i++) { msgMail.To = dt.Rows[i]["email"].ToString(); msgMail.Cc = "shweta.sharma@fresenius-kabi.com"; msgMail.From = mid; msgMail.Subject = "Document Has Been Approved"; msgMail.BodyFormat = MailFormat.Html; string strBody = "<html><body><b>Hello team,<br><br>The Document with the following detail has been approved<br><table>" + "<tr><td colspan=\"2\">Document Detail :-<br><br></td>" + "<tr><td>Document Code :</td> <td>" + dc + "</td></tr>" + "<tr><td>Author Name :</td> <td>" +AutName + "</td></tr>" + "<tr><td>File Name :</td> <td>" + FilName + "</td></tr>" + "<tr><td>Dodument Id :</td> <td>"+doc_id+"</td></tr>"+ "<tr><td>Document Status :</td> <td>"+Stat+"</td></tr>"+ "<tr><td>Upload Date :</td> <td>"+UpldDate+"</td></tr>"+ " </table><br></b>" + "<font color=\"blue\"><br><br>Thanks & Regards<br>" + nm + "</font></body></html>"; msgMail.Body = strBody; System.Web.Mail.SmtpMail.SmtpServer = "FRE-DE-RM-H03"; // this is the host server address SmtpMail.Send(msgMail); // here EXCEPTION IS OCCURING.... Response.Write("mail has been sent"); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)