I have an asp.net app that is sending out an email. Within the email, I want to attach a corporate logo in the signature area (below the main body). Looking at this site Embed image in Email – ASP.NET , C#
I get an error at
AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><body>" + msgBody, null, MediaTypeNames.Text.Html + "<br><img src=cid:companylogo/><br></body></html>");
The error is: The specified media type is invalid.
My code is:
msgBody += "Contact Email: " + contactemailaddr + "<br/><br/>";
LinkedResource logo = new LinkedResource("C:\\Data\\Images\\companylogo.jpg");
logo.ContentId = "corpLogo";
AlternateView av1 = AlternateView.CreateAlternateViewFromString("<html><body>" + msgBody, null, MediaTypeNames.Text.Html + "<br><img src=cid:companylogo/><br></body></html>");
av1.LinkedResources.Add(logo);
message.AlternateViews.Add(av1);
Any ideas what could be causing this?
Change the AlternateView line to be:
The problem is that you are appending the logo to the media type parameter. That parameter is just for the mime type of the message. The logo should be appended to the actual content parameter.