How to send an html email containing an image

Feb 25, 2013 at 12:35 PM
Hi,

Exists a function similar to LinkedResource/AlternateView classes of System.Net.Mail for to attachs the image contained into html body as resource?

Thanks
Coordinator
Feb 26, 2013 at 9:35 AM
Hi.

HigLabo does not have a class like LinkedResource/AlternateView now.
But I may implement this functionality in future release.
I'll review LinkedResource/AlternateView specification.

regards.
Feb 26, 2013 at 9:43 AM
Thanks,

It would really be a good thing because it would complement the already excellent library; now it's a pity I can only send html without local attached images.
I look forward to ...

Good job.
Coordinator
Mar 22, 2013 at 8:31 AM
Hi.
I wonder if the class necessary.
We can add linked photo by below code.

SmtpMessage mg = new SmtpMessage();
mg.Subject = "Photo of holiday";
mg.ContentType.Value = "text/html";
mg.BodyText = "<div style='font-size:20px;'>Hi. Good holiday photo to you!</div><img src=\"cid:image1\">";
SmtpContent ct = new SmtpContent();
ct["Content-ID"] = "image1";
ct.LoadFileData("C:\HolidayPhoto.png");


I will add it to documentation like this.
How to embed image
1.Create SmtpContent, LoadFileData and set content-id=image1.
2.Set html text of SmtpMessage as <img src=\"cid:image1\">
3.Set content-type of SmtpMessage to text/html.

How do you feel, that is enough or not?
Mar 22, 2013 at 5:16 PM
Hi,

Thanks for your answer ..

I tried, but image is always sent as real attachment, not embedded in html body; in the image position there is a square with an x

In my original html this is the image tag:

..
<img src="C:/TestHTML/FAT_R_file/medusa.jpg" /> ...

Than, I substitute the path with cid, here the code:

.....
.....
htmlPathFile = "C:/TestHTML/FAT_R_file/medusa.jpg"
resimage = "C:\TestHTML\FAT_R_file\medusa.jpg"
Dim cid As Guid = Guid.NewGuid()
HigLaboResource = New HigLabo.Net.Smtp.SmtpContent
HigLaboResource("Content-ID") = cid.ToString
HigLaboResource.LoadFileData(resImage)
HigLaboResource.ContentTransferEncoding = HigLabo.Net.Mail.TransferEncoding.Base64
htmlBody = Replace(htmlBody, htmlPathFile, "cid:" + cid.ToString)

smtpMessage.BodyText = htmlBody
smtpMessage.ContentType.Value = "text/html"
smtpMessage.Contents.Add(HigLaboResource)
.....
.....

What wrong?

Thanks in advance
Regards
Max
Coordinator
Mar 26, 2013 at 1:57 AM
Edited Mar 26, 2013 at 2:20 AM
Hi.Medusa.

I found a bug that the content-id does not set correctly.
I'll fix it and upload new version.
Please check it out!!

regards.
Apr 2, 2013 at 7:31 AM
Hi,

Great Higty, it Works.

Thanks
Regards
Max
Coordinator
Apr 2, 2013 at 2:38 PM
Thank you for your comment of new feature.
I wait for your next if you have.

sincerely