我必須通過SMTP
服務器發送郵件。我可以發送單個值。但是,我想發送List<>
值作爲郵件正文以表格格式或其他結構。我包括我的代碼如下:發送List <>值與身體在郵件 - SMTP服務器
MailMessage mailObj = new MailMessage("[email protected]", "[email protected]", "Reg : send mail",
"Emp Name :" + "Emp1" + Environment.NewLine + "Date From : " + Mon + "Date To : " + Fri);
SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com", ***);
SMTPServer.Host = "smtp.gmail.com";
SMTPServer.EnableSsl = true;
SMTPServer.Timeout = 200000;
SMTPServer.Credentials = new System.Net.NetworkCredential("[email protected]", "******");
SMTPServer.Send(mailObj);
我有我的價值觀的名單如下:
List<TimesheetValues> mailBody = new SampleDAO().GetDataForMail(dt1, satDate);
我怎麼能包括與車身和發送該List<>
值?
我嘗試以下操作:
List<TimesheetValues> Msg = new List<TimesheetValues>(); string strMsg = ""; int n=1;
foreach(var item in mailBody)
{
strMsg = strMsg + "<table><tr><td>" + n + "</td><td>" + item.Project_Name + "</td><td>" + item.Task_Name + "</td><td>" + item.Notes + "</td><td>" + item.Hrs_Worked + "</td></tr></table>";
n++;
}
strMsg = strMsg + "</br>";
MailMessage mailObj = new MailMessage("[email protected]", "[email protected]", "Reg : Timesheet",
"Emp Name :" + "Emp1" + Environment.NewLine + "Date From : " + Mon + "Date To : " + Fri);
mailObj.Body = "Emp Name : " + "Emp1" + Environment.NewLine + "Date From : " + Date2 + " Date To : " + Date6 + Environment.NewLine + strMsg;
現在我得到的所有記錄,但我已經在記錄TR TD標籤,且不顯示爲表。我該如何實現這個目標?
誰能幫助克服這一..提前 謝謝...