Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Using a .MHT File as a Log
Demonstrates how .mht and .eml files are identical. Both file types contain nothing more than MIME. It is only the file extension that is mapped to different default applications that makes them different. ' A Chilkat customer asked this question:
' This is exactly what we're looking to do.
' 1. Want to create a .MHT file with some header and other information and save it.
' 2. Open the same file and add an image(s) to this document save and close it
' 3. Open the same file and add some text to it and save and close it.
' 4. Open the same file and add another image(s)/text save and close it
' 5. Continue this process as long as we want or runs out of memory
' This example code is one possible solution:
' the mailman is only instantiated for unlocking...
Dim mailman As New Chilkat.MailMan()
mailman.UnlockComponent("anything")
' .mht files and .eml files are nothing more than MIME,
' the only difference is in the default programs associated with
' the file extension. For .mht it is a browser (IE), for .eml it is an
' email client (Outlook).
Dim email As New Chilkat.Email()
' Initialize the "MHT" with text and an image.
Dim cid As String
cid = email.AddRelatedFile("dudeRuby.gif")
' (You can download the GIF image here: http://chilkatsoft.com/images/dudeRuby.gif )
Dim initialText As String
initialText = "This is the initial text"
email.SetHtmlBody("<html><body><p>" + initialText + "<p>" + _
"<img src=""CID:" + cid + """></body></html>")
email.SaveEml("x1.mht")
' Now add another image...
Dim email2 As New Chilkat.Email()
email2.LoadEml("x1.mht")
cid = email2.AddRelatedFile("dudePython.gif")
' (You can download the GIF image here: http://chilkatsoft.com/images/dudePython.gif )
' Get the existing HTML body and add another image to it.
Dim html As String
html = email2.GetHtmlBody()
Dim newFragment As String
newFragment = "<p><img src=""CID:" + cid + """></body></html>"
html = html.Replace("</body></html>", newFragment)
email2.SetHtmlBody(html)
email2.SaveEml("x2.mht")
' Now add a line of text...
Dim email3 As New Chilkat.Email()
email3.LoadEml("x2.mht")
html = email3.GetHtmlBody()
html = html.Replace("</body></html>", "<p>This is the new text added...</body></html>")
email3.SetHtmlBody(html)
email3.SaveEml("x3.mht")
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.