0
string html = "<img src=data:image/png;base64,i0KGgAD34DtaA..........*>"; //*very long
SensMail(mailaddress,html, System.Text.Encoding.UTF8);

public static void SensMail(string sendTo, string body, System.Text.Encoding enCode)
{
            string emailaddress = "mail@gmail.com";
            string password = "it's secret";
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient();
            mail.From = new MailAddress(sendTo);
            mail.To.Add(sendTo);
            mail.BodyEncoding = enCode;
            mail.IsBodyHtml = true;
            mail.Subject = "subject";
            mail.Body = body;
            SmtpServer.UseDefaultCredentials = false;
            NetworkCredential NetworkCred = new NetworkCredential(emailaddress,password);
            SmtpServer.Credentials = NetworkCred;
            SmtpServer.EnableSsl = true;
            SmtpServer.Port = 587;
            SmtpServer.Host = "smtp.gmail.com";
            SmtpServer.Send(mail);
}

Why is the image not displayed ??

I tried to send to two different email providers, without success.

Is this happening for security reasons?

How can this problem be solved?

In HTML it does work and you see the image.

Amen
  • 15
  • 5
  • I don't think most email clients support data URIs. – Crowcoder Jun 23 '22 at 18:21
  • I can not view a picture? Does not make sense. – Amen Jun 23 '22 at 18:35
  • You shouldn't count on data URIs to work. You can embed pictures in other ways. – Crowcoder Jun 23 '22 at 19:11
  • No one suggested you can't do a QR code. What they said is that a data URI may not work, but there are other ways of embedding images in emails. Please make sure you take your time reading comments, which will help eliminate confusion. – mason Jun 23 '22 at 19:51

1 Answers1

3

Outlook doesn't understand base64 images. There are two possible ways:

  1. Upload the image file to any web server and then use the image URL in the HTML body for that image. Be aware, Outlook may block external links (even for images) automatically.

  2. You may add an image file as an attachment and then use the cid prefix for the img tag. See Send inline image in email for more information.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45