0

I want to send image in Mail body not a attachment.

Here is my code.

MailMessage mail = new MailMessage();
mail.To.Add(new MailAddress(""toaddress"));

mail.Subject = strSubject;
mail.Body = "<html><body><img src=cid:companylogo/><br><p>Dear Member,</p>" + strBody + "<br/><b>Regards</b>,<br/>Team</body></html>";
mail.IsBodyHtml = true;
AlternateView altView = AlternateView.CreateAlternateViewFromString(mail.Body, null, MediaTypeNames.Text.Html);

LinkedResource logo = new LinkedResource("logo.jpg", MediaTypeNames.Image.Jpeg);
logo.ContentId = "companylogo";
altView.LinkedResources.Add(logo);
mail.AlternateViews.Add(altView);
SmtpClient client = new SmtpClient();
client.Send(mail);

Using this I am getting image as an attachment.

How I will send it as a Mail body?

Raghuveer
  • 2,630
  • 3
  • 29
  • 59
user
  • 793
  • 4
  • 14
  • 23

1 Answers1

1

What you have to do is to send the image as an attachment, and then refer to int from your mail's HTML. It is explained here.

You can also refer to an image from an external server, most modern email clients will allow that.

Community
  • 1
  • 1
Dariusz
  • 21,561
  • 9
  • 74
  • 114