我正在处理一个必须发送带有附件的电子邮件的项目。我已经实现了发送邮件,但是我不知道如何附加一个excel文件。
有人能指出我正确的方向吗?到目前为止,这是我的代码:
private void sendmail(string Tomailid, string name)
{
MailMessage mail = new MailMessage();
mail.From = new MailAddress("ehsimsemail@gmail.com");
mail.To.Add(Tomailid);
mail.Subject = "Test Mail";
StringBuilder sb = new StringBuilder();
sb.Append("Dear ");
sb.Append(string.Format("{0} ", name));
//sb.Append("Yuvaraj");
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
sb.Append("UCR No : ");
sb.Append("3256987");
sb.Append(" ");
sb.Append("HAS BEEN SENT FOR YOUR REVIEW AND APPROVAL");
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
sb.Append("For action, Please click Here");
sb.Append(Environment.NewLine);
sb.Append("This is a automatic generated report from Advanced Incident Management System (EHS-IMS). Please do not reply to this mail.");
sb.Append(Environment.NewLine);
sb.Append(Environment.NewLine);
sb.Append("Thanks & Regards,");
sb.Append(Environment.NewLine);
sb.Append("EHSIMS TEAM");
mail.Body = sb.ToString();
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.Port = 587;
SmtpServer.EnableSsl = true;
SmtpServer.Credentials = new System.Net.NetworkCredential("ehsimsemail@gmail.com", "ehsims123");
SmtpServer.Send(mail);
}