We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Creating an MHT Email

I’d like to send HTML email with the images intact (or MHT format email). I generate the HTML, so how can I convert HTML to MHTML and make it the message body?


Thanks for considering Aspose.

Following is a simple example that sends an HTML email with an embedded image. You need to add object of type LinkedResource per image and add it to the LinkedResources collection of the MailMessage object.

// prepare the message

MailMessage msg = new MailMessage("from@domain.com", "to@domain.com");

msg.Subject = "sending html emails";

// set the src attribute as src=cid:sampleimage. sampleimage is the id of linked resource

msg.HtmlBody = "Attached below is a sample image.

" +


// add the linked resource. give the path of the image

LinkedResource image = new LinkedResource("c:\\temp\\sample.jpg");

// set the contentid to sampleimage. this is the id that is used in img tag

image.ContentId = "sampleimage";

// add the linked resource to message


// initialize the smtp client

SmtpClient client = new SmtpClient("mail.domain.com", "user@domain.com", "password");

// send the message


Thank you for that example. This will work if my image is on the local drive, however if the image is on a web server I use the url to the image when creating the LinkedResource. That throws the following exception:

System.ArgumentException: URI formats are not supported.

Do I have to stream the image into the LinkedResource? Before I attempt to do that, is it possible to include an image from a URI?

I typed too soon. Streaming the output from the URL does work! I do have to stream each graphic, but that’s ok. Thanks for the assistance.