问题
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\"\" />";
回答1:
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\" />";
来源:https://stackoverflow.com/questions/32665354/adding-img-html-tag-to-c-sharp-string