Click here to Skip to main content
16,016,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

i am geting the following exception...

from The requested body part was not found in this message.

the code for the function is as follows...

XML
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");
           }
       }
Posted

1 solution

You don't just set the "From" addresss to a text string - it needs to be a MailAddress.
Have a look at this: Sending an Email in C# with or without attachments: generic routine.[^]
 
Share this answer
 
Comments
Tushar1999 28-Feb-12 4:21am    
but ... i have retrived the mail id from the database table.. so i will have to store it in a string variable
OriginalGriff 28-Feb-12 4:29am    
Look at the tip - see what it does with the From string?

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