我需要在 c# 的邮件中附加 html 个附件

I need to attach html attachments in mail in c#

我在 excel 中有一个电子邮件 ID 列表,每个电子邮件 ID 都有一个要附加的图像,其 url 将写入 excel 的下一行。请帮我附上每张图片及其对应的图片。我已经编写了发送邮件的程序。这在必须附加文件的位置显示错误 Illegal characters in path 。 提前致谢。

请帮我解决这个问题。

{

        DataTable dtValues = SQLHelper.ExecuteDataset("Stored Procedure").Tables[2];
        if (dtValues.Rows.Count > 0)
            System.Console.Clear();
        foreach (DataRow row in dtValues.Rows)
        {
            string mailname = Convert.ToString(row["row1"]);
            string mailemail = Convert.ToString(row["row2"]);
            string Code = Convert.ToString(row["row3"]);
            string Code_new = Code.Replace("\t", "");
            string Id = Convert.ToString(row["row4"]);
            string str = AppDomain.CurrentDomain.BaseDirectory;
            string image = str + "Codes\" + Code_new + ".jpg";
            //string path = Microsoft.SqlServer.Server.MapPath("/HTMLPage.html");
            //string strPath = HttpContext.Current.Server.MapPath("~/HTML");

            //string body = string.Empty;
            StreamReader reader = new StreamReader("HTMLPage1.html");
            string readfile = reader.ReadToEnd();
            string body = "";
            body = readfile;
            body = body.Replace("{USERNAME}", mailname);
            body = body.Replace("{EMAILID}", mailemail);
            body = body.Replace("{CODE}", QRCode);
            body = body.Replace("{IMAGE}", image);

            MailMessage Msg = new MailMessage();
            Msg.From = new MailAddress("xxx@gmail.com"); // Sender e-mail address.
            Msg.To.Add(mailemail);
            Console.WriteLine(Id + " : " + mailemail);

            Msg.Subject = "QR Code";
            Msg.Body = "Hi";
            Attachment attachFile = new Attachment(body);
            Msg.Attachments.Add(attachFile);
            Msg.IsBodyHtml = true;
            SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");
            SmtpServer.Port = 587;
            SmtpServer.EnableSsl = true;
            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Credentials = new System.Net.NetworkCredential("xxx2694@gmail.com", "984621232312");
            SmtpServer.Send(Msg);

        }
 }

应该加个附件:

// Create file attachment
Attachment ImageAttachment = new Attachment(Server.MapPath(Convert.ToString(row["FilePath"])));

// Set the ContentId of the attachment, used in body HTML
ImageAttachment.ContentId = Convert.ToString(row["FileName"]);

// Add an image as file attachment
Msg.Attachments.Add(ImageAttachment);