无法显示SMTP上发送的图像 [英] Cannot display image sent on SMTP

查看:186
本文介绍了无法显示SMTP上发送的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道为什么我在outlook中使用smtpclient发送的电子邮件没有显示图像?



图像上的错误显示链接的图像无法显示



我的尝试:



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>

推荐答案

它与发送接收电子邮件客户端有一个阻止它的设置无关。



例如,outlook 2013将阻止链接,图像,我认为默认情况下所有HTML内容都在电子邮件中,因为像我这样的用户认为这些垃圾邮件。如果你想要它们显示你必须专门取消阻止它们。



作为发送者,我无法对我阻止它们的事实做什么,什么是垃圾邮件不是我的选择不是你的。所以一切都按预期工作,从编程点来看,你无能为力。
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.


这篇关于无法显示SMTP上发送的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆