0

I know that thats not a new question but i want to know that when i set image in my Email Body using the below C# code, why my image not show on mail

SmtpClient client = new SmtpClient();
MailMessage myMessage = new MailMessage();

String Body = "<img src=\"images/logo2.png\" style=\"width:75px; height:75px;\" />";

myMessage.To.Add(new MailAddress(txtemail.Text));
myMessage.Subject = "Subject";
myMessage.Body = Body;
myMessage.IsBodyHtml = true;

try
{
    client.Send(myMessage);
}
catch (Exception ex)
{
    Response.Write("Unable to send Email" + ex);
}

I am using asp.net c#.

user3834541
  • 161
  • 1
  • 7
  • 27
  • @ZoharPeled I want to set image without attechment – user3834541 Jun 14 '15 at 09:48
  • When you use a full URL for the image, the mail client will require a separate action of the user before the image is shown. This will not happen when you use a cid: link to an attachment or use a data-url. – Hans Kesting Jun 15 '15 at 09:13

1 Answers1

1

Email will be opened in an email client and doesn't know which web-application to access the image. So your image src shouldn't be relative to the application. Change the src to include the full url:

<img src=\"http://www.somedomain.nl/images/logo2.png\"

Test the url in a browser by taking the src value and try browsing it. If it doesn't work, the src value isn't retrievable.

Dacker
  • 892
  • 2
  • 8
  • 12
  • image file shows as an attachment which i don't want, how i resolved this issue – user3834541 Jun 15 '15 at 04:01
  • I don't expect it to be shown as an attachment, but that images are blocked and require users to unblock images first. Imo this is pretty normal nowadays and keeps your mail lightweight. For other alternatives and their pros and cons check out https://sendgrid.com/blog/embedding-images-emails-facts/ If you overlook those, maybe you will decide to stick with Linked Images after all. – Dacker Jun 15 '15 at 11:04