Esempio n. 1
0
        public void ChangeAttachedFileLinksImages()
        {
            var baseSmileUrl = FileLinksToAttachmentConvertor.BaseUrl;

            var doc = new HtmlDocument();

            doc.LoadHtml(HtmlBody);
            var linkNodes = doc.DocumentNode.SelectNodes("//img[@src and (contains(@src,'" + baseSmileUrl + "'))]");

            if (linkNodes == null)
            {
                return;
            }

            var fileLinksConvertor = new FileLinksToAttachmentConvertor();

            foreach (var linkNode in linkNodes)
            {
                var link = linkNode.Attributes["src"].Value;
                _logger.Info("ChangeAttachedFileLinksImages() Link to file link: {0}", link);
                var attach = fileLinksConvertor.ToMailAttachment(link);
                _logger.Info("ChangeAttachedFileLinksImages() Embedded file link contentId: {0}", attach.contentId);
                linkNode.SetAttributeValue("src", "cid:" + attach.contentId);

                if (AttachmentsEmbedded.All(x => x.contentId != attach.contentId))
                {
                    AttachmentsEmbedded.Add(attach);
                }
            }
            HtmlBody = doc.DocumentNode.OuterHtml;
        }
Esempio n. 2
0
        public void ChangeAttachedFileLinksImages()
        {
            var baseSmileUrl = FileLinksToAttachmentConvertor.BaseUrl;

            var doc = new HtmlDocument();
            doc.LoadHtml(HtmlBody);
            var linkNodes = doc.DocumentNode.SelectNodes("//img[@src and (contains(@src,'" + baseSmileUrl + "'))]");
            if (linkNodes == null) return;

            var fileLinksConvertor = new FileLinksToAttachmentConvertor();
            foreach (var linkNode in linkNodes)
            {
                var link = linkNode.Attributes["src"].Value;
                _logger.Info("ChangeAttachedFileLinksImages() Link to file link: {0}", link);
                var attach = fileLinksConvertor.ToMailAttachment(link);
                _logger.Info("ChangeAttachedFileLinksImages() Embedded file link contentId: {0}", attach.contentId);
                linkNode.SetAttributeValue("src", "cid:" + attach.contentId);

                if (AttachmentsEmbedded.All(x => x.contentId != attach.contentId))
                {
                    AttachmentsEmbedded.Add(attach);
                }
            }
            HtmlBody = doc.DocumentNode.OuterHtml;
        }