user
user

Reputation: 833

Send image in mail body

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?

Upvotes: 0

Views: 1670

Answers (1)

Dariusz
Dariusz

Reputation: 22241

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.

Upvotes: 1

Related Questions