Click here to Skip to main content
14,388,831 members
Rate this:
Please Sign up or sign in to vote.
Hi does anyone know why the email that i sent in outlook using smtpclient is not displaying the image??

the error on the image says "The linked image cannot be displayed"

What I have tried:

Outlook.Application app = new Outlook.Application();

            Outlook.MailItem item = (Outlook.MailItem)app.CreateItemFromTemplate(@"C:\Users\orculloj\Desktop\Sample2\tEST.msg", Type.Missing);

            string body = item.HTMLBody;

            string imgSrc = @"~\images\logo.png";
            string res = "";
            string bdy = "";
            string cid = "";

            var contentID = "logo";
            var inlineLogo = new Attachment(@"C:\Users\orculloj\Documents\Visual Studio 2013\Projects\WebApplication3\WebApplication3\images\logo.png");
            inlineLogo.ContentId = contentID;
            inlineLogo.ContentDisposition.Inline = true;
            inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;


            Match srcMatch = Regex.Match(item.HTMLBody, @"src=[""](?<url>[^""]+)[""]", RegexOptions.IgnoreCase);

            if (srcMatch.Success)
            {
                int srcIndex = srcMatch.ToString().IndexOf(srcMatch.ToString());
                if (srcIndex != -1)
                {
                    Match cidMatch = Regex.Match(srcMatch.ToString(), @"[""](?<url>[^""]+)[""]", RegexOptions.IgnoreCase);

                    if (cidMatch.Success)
                    {
                        int cidIndex = cidMatch.ToString().IndexOf(cidMatch.ToString());
                        if (cidIndex != -1)
                        {
                            string cd = @"""cid:" + contentID +"\"";
                            res = item.HTMLBody.Replace(cidMatch.ToString(), cd);
                            //bdy = string.Format(res, inlineLogo.ContentId);
                        }
                    }

                    //cid = res;
                }
            }

            MailMessage m = new MailMessage();

            // Address and send the message
            m.From = new MailAddress("DEV_MNL@altisource.com", "DEV_MNL");
            m.To.Add(new MailAddress("JohnEmmanuel.Orcullo@altisource.com", "Orcullo, John Emmanuel C"));
            m.Subject = "This is a test email";
            m.IsBodyHtml = true;
            m.Body = res;
            SmtpClient client = new SmtpClient("Internal-Mail.ascorp.com");
            client.Send(m);</url></url>
Posted
Updated 6-Apr-16 17:49pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

It has nothing to do with the sending the receiving email client has a setting that prevents it.

For example outlook 2013 will block links, images and I think all HTML stuff by default in emails because users like me consider such stuff spam. If you want them displayed you have to go an specifically unblock them.

As a sender there is nothing you can do about the fact I have blocked them, what is spam or not is my choice not yours. So everything is working as intended and from a programming point there is nothing you can do about it.
   
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100