2

I'm trying to email an image via Code behind but I can't get it to work. Basically trying to send the tag with a src so that it will display it in the email I sent:

Code behind

MailMessage mm = new MailMessage("mail-master@website.com", email);
mm.Subject = "Beta Signup";
string body = "<img src=\"\"http://popl.mpi-sws.org/2015/logos/google.png\"\" />";
mm.Body = body;
mm.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.Credentials = new System.Net.NetworkCredential("mail-master@website.com", "pass@123");
smtp.EnableSsl = true;
smtp.Send(mm);

However this doesn't send the image and I can't see the image showing up in the email I receive

string body = "<img src=\"\"http://popl.mpi-sws.org/2015/logos/google.png\"\" />";
Jay
  • 4,873
  • 7
  • 72
  • 137
  • possible duplicate of [Send inline image in email](http://stackoverflow.com/questions/18358534/send-inline-image-in-email) – Rahul Singh Sep 19 '15 at 07:14

1 Answers1

3

You are including two quotes to enclose the src attribute value.

"<img src=\"\"http://popl.mpi-sws.org/2015/logos/google.png\"\" />";

This will result in invalid HTML:

<img src=""http://popl.mpi-sws.org/2015/logos/google.png"" />

Try replacing with:

string body = "<img src=\"http://popl.mpi-sws.org/2015/logos/google.png\" />";
Saeb Amini
  • 23,054
  • 9
  • 78
  • 76