【问题标题】:how to send mail with image in windows service如何在 Windows 服务中发送带有图像的邮件
【发布时间】:2011-08-29 08:57:35
【问题描述】:

我有一个 Windows 服务来定期发送邮件。 我正在使用以下代码在邮件中嵌入图像 LinkedResource imagelink = new LinkedResource(HttpContext.Current.Server.MapPath("Images/header.png"), "image/png");

这在 Windows 服务中不起作用。

如果有其他方法,请向任何人提出建议。

【问题讨论】:

    标签: c# email windows-services


    【解决方案1】:

    Windows 服务未将正确的相对路径与 mappath 一起使用。尝试使用

    System.AppDomain.CurrentDomain.BaseDirectory + "/Images/header.png" 
    

    作为你的路径,看看是否可行

    【讨论】:

      【解决方案2】:

      HttpContext 仅在由 IIS 托管时可用。 Windows 服务基本上就像没有控制台的控制台应用程序。

      我会使用:

      ... = new LinkedResource(
              Path.Combine(Directory.GetCurrentDirectory(), "Images/header.png"),
              "image/png");
      

      【讨论】:

        猜你喜欢
        • 2013-01-30
        • 2013-04-29
        • 1970-01-01
        • 2011-01-26
        • 2013-06-01
        • 2011-06-01
        • 2017-04-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多