Question

Adding a jpeg picture to a mail message using

LinkedResource resPic = new LinkedResource(@"path\Pic.jpg", MediaTypeNames.Image.Jpeg); 

works well, but I need to add the picture from the project Properties.Resources.Pic.

How can that be done ?

Was it helpful?

Solution

One approach would be to save it to disk first:

var fileName = Guid.NewGuid.ToString();
var path = Path.Combine(
    Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)),
    fileName);
File.WriteAllBytes(path, Properties.Resources.Pic);

LinkedResource resPic = new LinkedResource(path, MediaTypeNames.Image.Jpeg);

and then when you're done with the whole process, clean up the file:

File.Delete(path);

I'm not guaranteeing that you'll be able to cleanup the file in the same method, so path may need to be a more accessible variable, but you can work out those details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top