Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# .NET如何将图像附加到电子邮件的html模板中_C#_.net - Fatal编程技术网

C# .NET如何将图像附加到电子邮件的html模板中

C# .NET如何将图像附加到电子邮件的html模板中,c#,.net,C#,.net,我正在尝试将一个图像附加到用于发送电子邮件的html模板中。 我试图使其工作的代码如下所示: string body = System.IO.File.ReadAllText("./Resources/templates/myTemplate.html"); byte[] imageArray = System.IO.File.ReadAllBytes(@"logo.jpg"); string base64ImageRepresentation = Con

我正在尝试将一个图像附加到用于发送电子邮件的html模板中。 我试图使其工作的代码如下所示:

string body = System.IO.File.ReadAllText("./Resources/templates/myTemplate.html");
byte[] imageArray = System.IO.File.ReadAllBytes(@"logo.jpg");
string base64ImageRepresentation = Convert.ToBase64String(imageArray);

body = body.Replace("{imageBase64}", base64ImageRepresentation);
myTemplate.html代码是:

<html>
<head></head>
   <body>
     <p>This is the email text</p>
     <img src={imageBase64}/>
   </body>
</html>

这是电子邮件文本

但是电子邮件没有被发送。 如果我删除了与图像相关的代码,电子邮件将正确发送


有人知道如何解决这个问题吗?

需要修改src的格式

src="data:image/png;base64, {imageBase64}"

如果这不起作用,考虑将字符集添加到图像SRC

src="data:image/png;charset=utf-8;base64, {imageBase64}"
你看到这个了吗?