如何在 Windows 服务中使用图像发送邮件
本文关键字:图像 Windows 服务 | 更新日期: 2023-09-27 17:57:08
我有一个Windows服务可以定期发送邮件。我使用以下代码在邮件中嵌入图像 LinkedResource imagelink = new LinkedResource(HttpContext.Current.Server.MapPath("Images/header.png"), "image/png");
这在 Windows 服务中不起作用。
如果有任何其他方法,请建议任何人。
Windows 服务不使用正确的相对路径和映射路径。尝试使用
System.AppDomain.CurrentDomain.BaseDirectory + "/Images/header.png"
作为您的路径,看看是否有效
HttpContext 仅在由 IIS 托管时可用。 Windows 服务基本上就像没有控制台的控制台应用程序。
我会使用:
... = new LinkedResource(
Path.Combine(Directory.GetCurrentDirectory(), "Images/header.png"),
"image/png");