Put a local image in the body when sending an email

2

To send an email from the application I'm using MailMessage made available. Now I'm trying to put an image in the body of the email via html:

MailMessage mail = new MailMessage();
SmtpClient SmtpCliente = new SmtpClient(server);
...
mail.IsBodyHtml = true;
mail.Body += "<br />Cumprimentos,<br />";
mail.Body += "<img src=\"D://MediaOleotorres/logoOleotorresAssinatura.png\" height=\"42\" width=\"42\">";

However, when you send the email, the image does not appear. Do I have to use an image that is available online?

EDIT: I've also tried to put the image as attached and then add it to the body, is it possible?

string attachmentPath = @"D:/MediaOleotorres/imagens/logoOleotorresAssinatura.png";
Attachment inline = new Attachment(attachmentPath);
inline.ContentDisposition.Inline = true;
inline.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
inline.ContentType.MediaType = "image/png";
inline.ContentType.Name = Path.GetFileName(attachmentPath);

mail.Attachments.Add(inline);
    
asked by anonymous 27.08.2014 / 11:22

1 answer

1

I have already found a solution, which consists of creating a new shortcut of the local image that you want to add to the body of the message and add the same to the body:

            var contentID = "Image";
            var inlineLogo = new Attachment(@"D://MediaOleotorres/logoOleotorresAssinatura.png/logoOleotorresAssinatura.png");
            inlineLogo.ContentId = contentID;
            inlineLogo.ContentDisposition.Inline = true;
            inlineLogo.ContentDisposition.DispositionType = DispositionTypeNames.Inline;
            mail.Attachments.Add(inlineLogo);
            mail.Body += "<br /><br /><img src=\"cid:" + contentID + "\" height=\"42\" width=\"42\"><br />";
    
27.08.2014 / 12:06