添加< img>HTML标记为C#字符串 [英] Adding <img> HTML tag to C# String
本文介绍了添加< img>HTML标记为C#字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过背后的Code通过电子邮件发送图像,但无法正常工作.基本上是尝试使用src发送标签,以便它将其显示在我发送的电子邮件中:
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:
背后的代码
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\"\" />";
推荐答案
您将包括两个引号来括住 src
属性值.
You are including two quotes to enclose the src
attribute value.
"<img src=\"\"http://popl.mpi-sws.org/2015/logos/google.png\"\" />";
这将导致无效的HTML:
This will result in invalid HTML:
<img src=""http://popl.mpi-sws.org/2015/logos/google.png"" />
尝试替换为:
string body = "<img src=\"http://popl.mpi-sws.org/2015/logos/google.png\" />";
这篇关于添加< img>HTML标记为C#字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文