我正在尝试在电子邮件的正文(内联)中插入图像,并且我能够插入图像。
但对于多张图片,我在这里面临艰难时期。
emailMessage.Body = "<div style=\"font-family:Arial\">This is an INLINE attachment:<br /><br /><img src=\"\\shared folder\image 1.png" alt=\"\"><br /><br />Thanks for downloading this example.</br><img src=\"\\shared folder\image 2.png" alt=\"\"> </br>
身体将如上所示。要做到这一点,我正在努力做到以下几点。
任何机构都可以建议如何使用C#语法实现这一功能。 示例电子邮件正文如下:
emailMessage.Body = "<div style=\"font-family:Arial\">This is an INLINE attachment:<br /><br /><img src=\"\\shared folder\image 1.png" alt=\"\"><br /><br />Thanks for downloading this example.</br><img src=\"\\shared folder\image 2.png" alt=\"\"> </br>;
//string strRegex = "/src=([^\\"]+)/";
//Regex srcRegex = new Regex(strRegex);
string[] immageArray = Regex.Split(emailMessage.Body, "<img src=");
//string[] immageArray = Regex.Match(emailMessage.Body, srcRegex,RegexOptions.None,Timesp);
foreach(string imgLine in immageArray)
{
attachmentPath = Environment.CurrentDirectory + imgLine;
// generate the contentID string using the datetime
contentID = Path.GetFileName(attachmentPath).Replace(".", "") + "@zofm";
// create the INLINE attachment
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentId = contentID;
inline.ContentType.MediaType = "image/png";
inline.ContentType.Name = Path.GetFileName(attachmentPath);
emailMessage.Attachments.Add(inline);
// replace the tag with the correct content ID
emailMessage.Body = emailMessage.Body.Replace("@@IMAGE@@", "cid:" + contentID);
}
但是我无法从emailMessage.Body中获取图像路径,任何人都能纠正这个吗? 谢谢。