图像未显示在 ASP 的 Outlook 中



发送电子邮件后,徽标不会显示在Outlook中,但它可以在Gmail中工作。

我发现在检查元素中,图像 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 访问将阻止任何图像 - 仅当用户选择显示/下载这些图像时,才会显示/下载这些图像。我不确定是否可以使用 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 中。

最新更新