0
votes

i have one windows service to send mail periodically. i am using following code to embed image in mail LinkedResource imagelink = new LinkedResource(HttpContext.Current.Server.MapPath("Images/header.png"), "image/png");

this is not working in windows service.

please suggest anyone if any other way of doing this.

2

2 Answers

0
votes

Windows Services do not use the proper relative path with mappath. Try using

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

as your path and see if that works

0
votes

HttpContext is only available when being hosted by IIS. A windows service is basically like a console application without a console.

I would use:

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