0

I want to send an email with a logo, but the image is blank in inbox

Here is the code:

 MailMessage msg = new MailMessage();
 msg.From = new MailAddress(txtEmail.Text);

 StringBuilder message = new StringBuilder();
 message.AppendLine("<img src=@'images/logo.png' />");
 message.AppendLine("<p>" + txtBody.Text + "</p>");

 msg.Body = message.ToString();
 msg.To.Add(txtTo.Text);
 msg.IsBodyHtml = true;

 SmtpClient client = new SmtpClient();

 client.UseDefaultCredentials = false;
 client.Credentials = new NetworkCredential(txtEmail.Text, txtPassword.Text);
 client.Host = "Smtp.gmail.com";
 client.Port = 587;
 client.EnableSsl = true;
 client.Send(msg);
Amir Nassal
  • 409
  • 2
  • 7
  • 22

2 Answers2

1

Problem is in the below line where you are providing a relative path for the image which is not going to work. You need to provide a absolute path for the image else your email client won't be able to download the image since it won't know from where to download.

message.AppendLine("<img src=@'images/logo.png' />");

Should be something like

message.AppendLine("<img src='www.somesitename.com/storage/logo.ong' />");
Rahul
  • 76,197
  • 13
  • 71
  • 125
0

you are inserting the image using html image tag and you specified a path to it. What it means is that when the user opens up the mail the browser is going to try to find that image using the given relative path.

Assuming you are opening it up using gmail its going to try to look for the image under gmail.com/images/logo.png. Its either going to find gmail's logo or 404 not found

What you want to do is to include the full path of the image

Steve
  • 11,696
  • 7
  • 43
  • 81