Sign In  Sign Up Live-Chat

Creating an MHT Email

Last post 06-11-2008, 2:51 PM by tonyamos. 3 replies.
Sort Posts: Previous Next
  •  06-10-2008, 6:55 PM 130856

    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?
    Filed under: MHT HTML
     
  •  06-11-2008, 5:07 AM 130908 in reply to 130856

    Re: Creating an MHT Email

    Hi,

    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.<br><br>" +

    "<img src=cid:sampleimage>";

    // 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

    msg.LinkedResources.Add(image);

    // initialize the smtp client

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

    // send the message

    client.Send(msg);


    Best Regards,

    Saqib Razzaq
    Support Developer
    Aspose Guangzhou Team

     
  •  06-11-2008, 1:26 PM 130975 in reply to 130908

    Re: Creating an MHT Email

    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?

     
  •  06-11-2008, 2:51 PM 130984 in reply to 130975

    Re: Creating an MHT Email

    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.
     
View as RSS news feed in XML