PatternImageInBody = @"<img\s*src=""(\.\.)?/files/images/\d+/({#filename})""\s*/>";

 

 for (int i = 0; i < imagesInBody.Count; i++)
            {
                string pattern = patternImageInBody.Replace("{#filename}", Regex.Escape(Path.GetFileName(imagesInBody[i]).ToLower()));
                if (Regex.IsMatch(Email.Body,pattern, RegexOptions.IgnoreCase))
                {
                    System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(imagesInBody[i]);
                    Email.Attachments.Add(attachment);
                    Email.Body = Regex.Replace(Email.Body, pattern, "<img src=\"cid:" + attachment.ContentId + "\"/>", RegexOptions.IgnoreCase);
                }
            }

 

主要是将邮件内容的HTML标识<img.../> 重新替换成红色部分,这样图片就可以作为附件附加在邮件上

相关文章:

  • 2022-02-15
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
  • 2021-06-10
  • 2021-10-18
猜你喜欢
  • 2022-12-23
  • 2022-02-25
  • 2022-12-23
  • 2022-01-04
  • 2021-10-02
  • 2021-07-17
相关资源
相似解决方案