我正面临着电子邮件的问题.... [英] i am faceing the problem with email ....
本文介绍了我正面临着电子邮件的问题....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我收到以下异常...
在此消息中找不到来自请求的正文部分.
该函数的代码如下...
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...
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");
}
}
推荐答案
您不只是将发件人"地址设置为文本字符串-它必须是MailAddress.
看看以下内容:在C#中使用以下方式发送电子邮件或没有附件:通用例程. [ ^ ]
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.[^]
这篇关于我正面临着电子邮件的问题....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文