Skip to main content
added 34 characters in body
Source Link
Marek Musielak
  • 24.2k
  • 3
  • 31
  • 64

I tried to send the email with an image in the body of email, the image is not an attachment.

I read the image from the media item in sitecore and i got the url of the image like https://domain/-/media/image.ashx next step i convert to email body using LinkedResource like below code

System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(imageUrl, "image/jpg"); imageResource.ContentId = "HDIImage"; System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<image src=cid:" + imageResource.ContentId + ">" + textbody, null, "text/html"); htmlView.LinkedResources.Add(imageResource);

System.Net.Mail.LinkedResource imageResource = new 
System.Net.Mail.LinkedResource(imageUrl, "image/jpg");
imageResource.ContentId = "HDIImage";
System.Net.Mail.AlternateView htmlView = 
System.Net.Mail.AlternateView.CreateAlternateViewFromString("<image src=cid:" + 
imageResource.ContentId + ">" + textbody, null, "text/html");
htmlView.LinkedResources.Add(imageResource);

but iI have exception like the image path is not given correctly.

I tried to send the email with an image in the body of email, the image is not an attachment.

I read the image from the media item in sitecore and i got the url of the image like https://domain/-/media/image.ashx next step i convert to email body using LinkedResource like below code

System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(imageUrl, "image/jpg"); imageResource.ContentId = "HDIImage"; System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<image src=cid:" + imageResource.ContentId + ">" + textbody, null, "text/html"); htmlView.LinkedResources.Add(imageResource);

but i have exception like the image path is not given correctly.

I tried to send the email with an image in the body of email, the image is not an attachment.

I read the image from the media item in sitecore and i got the url of the image like https://domain/-/media/image.ashx next step i convert to email body using LinkedResource like below code

System.Net.Mail.LinkedResource imageResource = new 
System.Net.Mail.LinkedResource(imageUrl, "image/jpg");
imageResource.ContentId = "HDIImage";
System.Net.Mail.AlternateView htmlView = 
System.Net.Mail.AlternateView.CreateAlternateViewFromString("<image src=cid:" + 
imageResource.ContentId + ">" + textbody, null, "text/html");
htmlView.LinkedResources.Add(imageResource);

but I have exception like the image path is not given correctly.

Source Link
Rameshkumar
  • 686
  • 1
  • 6
  • 16

Send Email with Images in body not Attachement in Sitecore

I tried to send the email with an image in the body of email, the image is not an attachment.

I read the image from the media item in sitecore and i got the url of the image like https://domain/-/media/image.ashx next step i convert to email body using LinkedResource like below code

System.Net.Mail.LinkedResource imageResource = new System.Net.Mail.LinkedResource(imageUrl, "image/jpg"); imageResource.ContentId = "HDIImage"; System.Net.Mail.AlternateView htmlView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<image src=cid:" + imageResource.ContentId + ">" + textbody, null, "text/html"); htmlView.LinkedResources.Add(imageResource);

but i have exception like the image path is not given correctly.