0

I'm trying to send an email with a message that includes an image. This is how I wrote the html code:

<body>
  <div class="container">
    <img class="icon" src="cid:{0}">
    <div class="error">{title}</div>
    <div class="message">
      {message}
      <br> {path}
      <br>Date : {date}
      <br>Please verify the mentioned directory.
    </div>
  </div>
</body>

and this the .net code in which I try to send the message to the html template:

string body = string.Empty;
WebClient clients = new WebClient();
body = clients.DownloadString(@"C:\templete.html");
body = body.Replace("{title}", "unreachable source path");
body = body.Replace("{message}", " unable to reach destination folder on: \"");
body = body.Replace("{path}", sourcePath);
body = body.Replace("{date}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
var builder = new BodyBuilder();
builder.HtmlBody = body;
var image = builder.LinkedResources.Add(@"C:Resources\images.jpg");
image.ContentId = MimeKit.Utils.MimeUtils.GenerateMessageId();
builder.HtmlBody = String.Format(body, image.ContentId);

sendEmail(" notification", body);

sendEmail takes the object and the message so I get the email, but without the images. what is wrong?

I tried also the put the path of the image direct on the html template but it doesn't work also

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
ing23
  • 1
  • 2
    Does this answer your question? [embedding image in html](https://stackoverflow.com/questions/6706891/embedding-image-in-html-email) – Dour High Arch Apr 04 '23 at 15:39

0 Answers0