Reputation: 124
I am building a e-mail body up with a StringBuilder. I need to insert a image at the end of the e-mail as a signature.
My image is located a folder in my MVC solution. The source to the image I can browse, and that works.
if I do browse to: http://localhost/Content/images/CustomerSatisfaction.jpg, I get the image returned, just now to get this image as part of the body of the email
string imgSrc = string.Format("@{0}{1}", HttpContext.Current.Request.Url.Authority,
"/Content/images/CustomerSatisfaction.jpg");
StringBuilder sb = new StringBuilder();
sb.AppendLine("<html>");
sb.AppendLine("<body>");
sb.AppendLine(string.Format("<img src='{0}' alt='xxx'>", imgSrc));
sb.AppendLine("</body>");
sb.AppendLine("</html>");
I have also tried several versions for my image source:
string imgSrc = "~/Content/images/CustomerSatisfaction.jpg";
Upvotes: 1
Views: 2704
Reputation: 3587
Images need to be hosted externally inside emails or embedded.
I would recommend external hosting as it is the easiest to do and allows for lightweight emails (potential increase in deliverability). Embedded images are not displayed in some email clients, so that may cause issues as well.
See this article for some good in-depth info into External link vs. Embedding images. https://sendgrid.com/blog/embedding-images-emails-facts/
Below is quick synopsis of article:
CID Embedded Images (Inline Images)
Pros
Cons
Inline Embedding (Base64 Encoding)
Pros
Cons
Linked Images
Pros
Cons
Upvotes: 2