I'm having some difficulty embedding an image from the Properties.Resources to a MailMessage, currently the image does not show in the email i receive.
I have successfully embedded the image from a directory location but would prefer if the image came from memory/the application.
Here is a simplified version of what I am doing.
Bitmap b = new Bitmap(Properties.Resources.companyLogo);
MemoryStream logo = new MemoryStream();
b.Save(logo, ImageFormat.Jpeg);
MailMessage newEmail = new MailMessage(from, to);
newEmail.Subject = subject;
newEmail.IsBodyHtml = true;
LinkedResource footerImg = new LinkedResource(logo, "image/jpeg");
footerImg.ContentId = "companyLogo";
AlternateView foot= AlternateView.CreateAlternateViewFromString(body + "<p> <img src=cid:companyLogo /> </p>", null, "text/html");
foot.LinkedResources.Add(footerImg);
newEmail.AlternateViews.Add(foot);
SmtpClient server = new SmtpClient(host, port);
server.Send(newEmail);
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…