ASP 中的 Outlook 中未显示图像

Image not displayed in Outlook in ASP

发送电子邮件后,徽标未显示在 Outlook 中,但在 Gmail 中有效。

我发现在inspect元素中,图片src变成了blockedimagesrc

在我的控制器中:

var NotifyCompany = new NotifyCompany()
{
   Email = model.regE,
   EmailTo = contact.GetPropertyValue<string>("email"),
   DateRegistered = DateTime.UtcNow
};
EmailHelpers.SendEmail(NotifyCompany, "NotifyCompany", "New Client Registered");

帮手:

public static ActionResponse SendEmail(IEmail model, string emailTemplate, string subject, List<HttpPostedFileBase> files = null)
{
    try
    {
        var template =
        System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath(string.Format("~/Templates/{0}.cshtml", emailTemplate)));
        var body = Razor.Parse(template, model);

        var attachments = new List<Attachment>();
        if (files != null && files.Any())
        {
            foreach (var file in files)
            {
                var att = new Attachment(file.InputStream, file.FileName);
                attachments.Add(att);
            }
        }

        var email = Email
        .From(ConfigurationManager.AppSettings["Email:From"], "myWebsiteEmail")
        .To(model.EmailTo)
        .Subject(subject)
        .Attach(attachments)
        .Body(body).BodyAsHtml();

        email.Send();
        return new ActionResponse()
        {
            Success = true
        };
    }
    catch (Exception ex)
    {
        return new ActionResponse()
        {
            Success = false,
            ErrorMessage = ex.Message
        };
    }
}

在我的电子邮件模板中:

<img src="/mysite.com/image/logo.png"/>

如有任何帮助,我们将不胜感激。

默认情况下,Outlook Web 访问会阻止任何图像 - 只有当用户选择 display/download 图像时,这些图像才会 displayed/downloaded。我不确定是否可以使用 Office 365 管理中心或 OWA 设置来调整默认行为。

前段时间可以通过将其用作 table>tr>td 单元格 background-image css 属性 中的背景图像来解决此问题。

编辑

查看了我最近的一个项目,我们正在发送有关工单的通知邮件。站点徽标在 outlook/owa 中正确显示 - 未将收件人添加到受信任列表:

            using (MailMessage mm = new MailMessage(sender, header.RecipientAddress, header.Subject, header.Body))
            {
                mm.Body = header.Body;
                mm.BodyEncoding = Encoding.UTF8;
                mm.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                mm.Priority = priority == IntMailPriority.High ? MailPriority.High : MailPriority.Normal;
                mm.IsBodyHtml = bodyIsHtml;

                // logo
                if (bodyIsHtml)
                {
                    AlternateView htmlView = AlternateView.CreateAlternateViewFromString(header.Body, Encoding.UTF8, "text/html");

                    string logoPath = $"{AppDomain.CurrentDomain.BaseDirectory}\images\logo_XXX.png";
                    LinkedResource siteLogo = new LinkedResource(logoPath)
                        {
                            ContentId = "logoId"
                        };
                    htmlView.LinkedResources.Add(siteLogo);
                    mm.AlternateViews.Add(htmlView);
                }

                // create smtpclient
                SmtpClient smtpClient = new SmtpClient(smtpSettings.ServerAddress, smtpSettings.Port)
                                    {
                                        Timeout = 30000,
                                        DeliveryMethod = SmtpDeliveryMethod.Network
                                    };
                // set relevant smtpclient settings 
                if (smtpSettings.UseTlsSsl)
                {
                    smtpClient.EnableSsl = true;

                    // needed for invalid certificates
                    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
                }
                if (smtpSettings.UseAuth)
                {
                    smtpClient.UseDefaultCredentials = false;

                    NetworkCredential smtpAuth = new NetworkCredential { UserName = smtpSettings.Username, Password = smtpSettings.Password };
                    smtpClient.Credentials = smtpAuth;
                }

                smtpClient.Timeout = smtpSettings.SendingTimeout * 1000;

                // finally sent mail \o/ :)
                try
                {
                    smtpClient.Send(mm);
                }
                catch (SmtpException exc)
                {
                    throw new ProgramException(exc, exc.Message);
                }
                catch (InvalidOperationException exc)
                {
                    throw new ProgramException(exc, exc.Message);
                }
                catch (AuthenticationException exc)
                {
                    throw new ProgramException(exc, exc.Message);
                }
            }

之后标志被称为

<IMG alt="Intex Logo" src="cid:logoId">

在生成的 html 中。