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\"\" />";
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\" />";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.