[英]Adding <img> HTML tag to C# String
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:
基本上是尝试使用src发送标签,以便将其显示在我发送的电子邮件中:
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. 您将使用两个引号将
src
属性值括起来。
"<img src=\"\"http://popl.mpi-sws.org/2015/logos/google.png\"\" />";
This will result in invalid HTML: 这将导致无效的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\" />";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.