CkMht Python Programming
Reference Documentation

CkMht

Chilkat MHT can generate email objects from HTML files and URLs, and convert HTML to MHT or EML files.

Object Creation

obj = chilkat.CkMht()

Properties

# str is a CkString object (output)
get_BaseUrl( str )

# newVal is a string (input)
put_BaseUrl( newVal )

When processing an HTML file or string (not a website URL), this defines the base URL to be used when converting relative HREFs to absolute HREFs.

# Returns an integer value
get_ConnectTimeout( )

# newVal is an integer (input)
put_ConnectTimeout( newVal )

The amount of time in seconds to wait before timing out when connecting to an HTTP server. The default value is 10 seconds.

# str is a CkString object (output)
get_DebugHtmlAfter( str )

# newVal is a string (input)
put_DebugHtmlAfter( newVal )

A filename to save the result HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.

# str is a CkString object (output)
get_DebugHtmlBefore( str )

# newVal is a string (input)
put_DebugHtmlBefore( newVal )

A filename to save the input HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.

# Returns a boolean value
get_DebugTagCleaning( )

# newVal is a boolean (input)
put_DebugTagCleaning( newVal )

When True causes the Mht class to be much more verbose in its logging. The default is False.

# Returns a boolean value
get_EmbedImages( )

# newVal is a boolean (input)
put_EmbedImages( newVal )

Controls whether images are embedded in the MHT/EML, or whether the IMG SRC attributes are left as external URL references. If false, the IMG SRC tags are converted to absolute URLs (if necessary) and the images are not embedded within the MHT/EML.

# Returns a boolean value
get_EmbedLocalOnly( )

# newVal is a boolean (input)
put_EmbedLocalOnly( newVal )

If True, only images found on the local filesystem (i.e. links to files) will be embedded within the MHT.

# Returns a boolean value
get_FetchFromCache( )

# b is a boolean (input)
put_FetchFromCache( b )

If True, page parts such as images, style sheets, etc. will be fetched from the disk cache if possible. The disk cache root may be defined by calling AddCacheRoot. The default value is False.

# Returns a boolean value
get_IgnoreMustRevalidate( )

# b is a boolean (input)
put_IgnoreMustRevalidate( b )

Some HTTP responses contain a "Cache-Control: must-revalidate" header. If this is present, the server is requesting that the client always issue a revalidate HTTP request instead of serving the page directly from cache. If IgnoreMustRevalidate is set to True, then Chilkat MHT will serve the page directly from cache without revalidating until the page is no longer fresh. (assuming that FetchFromCache is set to True)

The default value of this property is False.

# Returns a boolean value
get_IgnoreNoCache( )

# b is a boolean (input)
put_IgnoreNoCache( b )

Some HTTP responses contain headers of various types that indicate that the page should not be cached. Chilkat MHT will adhere to this unless this property is set to True.

The default value of this property is False.

# str is a CkString object (output)
LastErrorHtml( str )

To be documented soon.Error information in HTML format for the last method called.

# str is a CkString object (output)
LastErrorText( str )

Error information in plain-text format for the last method called.

# str is a CkString object (output)
LastErrorXml( str )

Error information in XML format for the last method called.

# Returns a boolean value
get_NoScripts( )

# newVal is a boolean (input)
put_NoScripts( newVal )

Only applies when creating MHT files. Scripts are always removed when creating EML or emails from HTML. If set to True, then all scripts are removed, if set to False (the default) then scripts are not removed.

# Returns a boolean value
get_NtlmAuth( )

# newVal is a boolean (input)
put_NtlmAuth( newVal )

Setting this property to True causes the MHT component to use NTLM authentication (also known as IWA -- or Integrated Windows Authentication) when authentication with an HTTP server.

The default value of this property is False.

# Returns an integer value
get_NumCacheLevels( )

# v is an integer (input)
put_NumCacheLevels( v )

The number of directory levels to be used under each cache root. The default is 0, meaning that each cached item is stored in a cache root directory. A value of 1 causes each cached page to be stored in one of 255 subdirectories named "0","1", "2", ..."255" under a cache root. A value of 2 causes two levels of subdirectories ("0..255/0..255") under each cache root. The MHT control automatically creates subdirectories as needed. The reason for mutliple levels is to alleviate problems that may arise when huge numbers of files are stored in a single directory. For example, Windows Explorer does not behave well when trying to display the contents of directories with thousands of files.

# Returns an integer value
get_NumCacheRoots( )

The number of cache roots to be used for the disk cache. This allows the disk cache spread out over multiple disk drives. Each cache root is a string indicating the drive letter and directory path. For example, "E:\Cache". To create a cache with four roots, call AddCacheRoot once for each directory root.

# Returns a boolean value
get_PreferMHTScripts( )

# newVal is a boolean (input)
put_PreferMHTScripts( newVal )

This property provides a means for the noscript option to be selected when possible. If PreferMHTScripts = False, then scripts with noscript alternatives are removed and the noscript content is kept. If True (the default), then scripts are preserved and the noscript options are discarded.

# str is a CkString object (output)
get_Proxy( str )

# newVal is a string (input)
put_Proxy( newVal )

(Optional) A proxy host:port if a proxy is necessary to access the Internet. The proxy string should be formatted as "hostname:port", such as "www.chilkatsoft.com:100".

# str is a CkString object (output)
get_ProxyLogin( str )

# newVal is a string (input)
put_ProxyLogin( newVal )

If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy login.

# str is a CkString object (output)
get_ProxyPassword( str )

# newVal is a string (input)
put_ProxyPassword( newVal )

If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy password.

# Returns an integer value
get_ReadTimeout( )

# newVal is an integer (input)
put_ReadTimeout( newVal )

The amount of time in seconds to wait before timing out when reading from an HTTP server. The ReadTimeout is the amount of time that needs to elapse while no additional data is forthcoming. During a long data transfer, if the data stream halts for more than this amount, it will timeout. Otherwise, there is no limit on the length of time for the entire data transfer.

The default value is 20 seconds.

# Returns a boolean value
get_UpdateCache( )

# b is a boolean (input)
put_UpdateCache( b )

Controls whether the cache is automatically updated with the responses from HTTP GET requests. If True, the disk cache is updated, if False (the default), the cache is not updated.

# Returns a boolean value
get_UseCids( )

# newVal is a boolean (input)
put_UseCids( newVal )

Controls whether CID URLs are used for embedded references when generating MHT or EML documents. If UseCids is False (the default), then URLs are left unchanged and the embedded items will contain "content-location" headers that match the URLs in the HTML. If True, CIDs are generated and the URLs within the HTML are replaced with "CID:" links.

# Returns a boolean value
get_UseFilename( )

# newVal is a boolean (input)
put_UseFilename( newVal )

If True, a "filename" attribute is added to each Content-Disposition MIME header field for each embedded item (image, style sheet, etc.). If False, then no filename attribute is added.

The default value of this property is True.

# Returns a boolean value
get_UseIEProxy( )

# newVal is a boolean (input)
put_UseIEProxy( newVal )

If True, the proxy host/port used by Internet Explorer will also be used by Chilkat MHT.

# Returns a boolean value
get_UseInline( )

# newVal is a boolean (input)
put_UseInline( newVal )

If True, an "inline" attribute is added to each Content-Disposition MIME header field for each embedded item (image, style sheet, etc.). If False, then no inline attribute is added.

The default value of this property is True.

# Returns a boolean value
get_Utf8( )

# b is a boolean (input)
put_Utf8( b )

When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.

# str is a CkString object (output)
get_Version( str )

The version of the component, such as "1.0.0"

# str is a CkString object (output)
get_WebSiteLogin( str )

# newVal is a string (input)
put_WebSiteLogin( newVal )

(Optional) Specifies the login if a a Web page is accessed that requires a login

# str is a CkString object (output)
get_WebSitePassword( str )

# newVal is a string (input)
put_WebSitePassword( newVal )

Optional) Specifies the password if a a Web page is accessed that requires a login and password

Methods

# dir is a string (input)
AddCacheRoot( dir )

If disk caching is used, this must be called once for each cache root. For example, if the cache is spread across D:\cacheRoot, E:\cacheRoot, and F:\cacheRoot, an application would setup the cache object by calling AddRoot three times -- once with "D:\cacheRoot", once with "E:\cacheRoot", and once with "F:\cacheRoot".

# name is a string (input)
# value is a string (input)
AddCustomHeader( name, value )

Adds a custom HTTP header to all HTTP requests sent by the MHT component. To add multiple header fields, call this method once for each custom header.

# url is a string (input)
AddExternalStyleSheet( url )

(This method rarely needs to be called.) Includes an additional style sheet that would not normally be included with the HTML. This method is provided for cases when style sheet names are constructed and dynamically included in Javascript such that MHT .NET cannot know beforehand what stylesheet to embed. MHT .NET by default downloads and embeds all stylesheets externally referenced by the HTML

ClearCustomHeaders( )

Removes all custom headers that may have accumulated from previous calls to AddCustomHeader.

# pattern is a string (input)
ExcludeImagesMatching( pattern )

(This method rarely needs to be called.) Tells Chilkat MHT .NET to not embed any images whose URL matches a pattern. Sometimes images can be referenced within style sheets and not actually used when rendering the page. In cases like those, the image will appear as an attachment in the HTML email. This feature allows you to explicitly remove those images from the email so no attachments appear.

# url_or_htmlFilepath is a string (input)
# outputEmlFilename is a string (input)
# Returns a boolean value
GetAndSaveEML( url_or_htmlFilepath, outputEmlFilename )

Creates an EML file from a web page or HTML file. All external images and style sheets are downloaded and embedded in the EML file.

Returns True for success, False for failure.

# url_or_htmlFilepath is a string (input)
# outputMhtFilename is a string (input)
# Returns a boolean value
GetAndSaveMHT( url_or_htmlFilepath, outputMhtFilename )

Creates an MHT file from a web page or local HTML file. All external images, scripts, and style sheets are downloaded and embedded in the MHT file.

Returns True for success, False for failure.

# url_or_htmlFilepath is a string (input)
# zipEntryFilename is a string (input)
# zipFilename is a string (input)
# Returns a boolean value
GetAndZipEML( url_or_htmlFilepath, zipEntryFilename, zipFilename )

Creates an EML file from a web page or HTML file, compresses, and appends to a new or existing Zip file. All external images and style sheets are downloaded and embedded in the EML.

Returns True for success, False for failure.

# url_or_htmlFilepath is a string (input)
# zipEntryFilename is a string (input)
# zipFilename is a string (input)
# Returns a boolean value
GetAndZipMHT( url_or_htmlFilepath, zipEntryFilename, zipFilename )

Creates an MHT file from a web page or HTML file, compresses, and appends to a new or existing Zip file. All external images and style sheets are downloaded and embedded in the MHT.

Returns True for success, False for failure.

# index is an integer (input)
# str is a CkString object (output)
# Returns a boolean value
GetCacheRoot( index, str )

Returns the Nth cache root (indexing begins at 0). Cache roots are set by calling AddCacheRoot one or more times.

Returns True for success, False for failure.

# url_or_htmlFilepath is a string (input)
# eml is a CkString object (output)
# Returns a boolean value
GetEML( url_or_htmlFilepath, eml )

Creates EML from a web page or HTML file, and returns the EML (MIME) message data as a string.

Returns True for success, False for failure.

# url_or_htmlFilePath is a string (input)
# Returns a CkEmail object
GetEmail( url_or_htmlFilePath )

Downloads a web page and creates an HTML Email object that can be sent using Chilkat Email component. Embedded within the email are all the images and style sheets referenced from the web page.

Returns a null reference on failure.

Returns a null reference on failure

# url_or_htmlFilepath is a string (input)
# mht is a CkString object (output)
# Returns a boolean value
GetMHT( url_or_htmlFilepath, mht )

Creates MHT from a web page or local HTML file, and returns the MHT (MIME) message data as a string

Returns True for success, False for failure.

# url_or_htmlFilePath is a string (input)
# Returns a CkMime object
GetMime( url_or_htmlFilePath )

Converts a web Page (URL) or HTML file to a Chilkat Mime object. Returns a null reference on failure.

# htmlText is a string (input)
# eml is a CkString object (output)
# Returns a boolean value
HtmlToEML( htmlText, eml )

Creates an in-memory EML string from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the EML string that is returned.

Returns True for success, False for failure.

# html is a string (input)
# emlFilename is a string (input)
# Returns a boolean value
HtmlToEMLFile( html, emlFilename )

Creates an EML file from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the EML file.

Returns True for success, False for failure.

# htmlText is a string (input)
# Returns a CkEmail object
HtmlToEmail( htmlText )

Creates an email object from an in-memory HTML string. Returns a null reference on failure.

Returns a null reference on failure

# htmlText is a string (input)
# mht is a CkString object (output)
# Returns a boolean value
HtmlToMHT( htmlText, mht )

Creates an in-memory MHT web archive from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the MHT string.

Returns True for success, False for failure.

# html is a string (input)
# mhtFilename is a string (input)
# Returns a boolean value
HtmlToMHTFile( html, mhtFilename )

Creates an MHT file from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the MHT file.

Returns True for success, False for failure.

# Returns a boolean value
IsUnlocked( )

Returns True if the MHT component is unlocked.

# name is a string (input)
RemoveCustomHeader( name )

Removes a custom header by header field name.

RestoreDefaults( )

Restores the default property settings.

# filename is a string (input)
# Returns a boolean value
SaveLastError( filename )

Saves the last error information to an XML formatted file.

# unlockCode is a string (input)
# Returns a boolean value
UnlockComponent( unlockCode )

Unlocks the component allowing for the full functionality to be used. Returns True if the unlock code is valid.

# mhtFilename is a string (input)
# unpackDir is a string (input)
# outputHtmlFilename is a string (input)
# partsSubDir is a string (input)
# Returns a boolean value
UnpackMHT( mhtFilename, unpackDir, outputHtmlFilename, partsSubDir )

Unpacks the contents of a MHT file. The destination directory is specified by unpackDir. The name of the HTML file created is specified by outputHtmlFilename, and supporting files (images, javascripts, etc.) are created in partsSubDir, which is automatically created if it does not already exist.

Returns True for success, False for failure.

# mhtString is a string (input)
# unpackDir is a string (input)
# outputHtmlFilename is a string (input)
# partsSubDir is a string (input)
# Returns a boolean value
UnpackMHTString( mhtString, unpackDir, outputHtmlFilename, partsSubDir )

Same as UnpackMHT, except the MHT is passed in as an in-memory string.

Returns True for success, False for failure.

# Returns a string
baseUrl( )

When processing an HTML file or string (not a website URL), this defines the base URL to be used when converting relative HREFs to absolute HREFs.

# Returns a string
debugHtmlAfter( )

A filename to save the result HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.

# Returns a string
debugHtmlBefore( )

A filename to save the input HTML when converting a URL, file, or HTML string. If problems are experienced, the before/after HTML can be analyzed to help determine the cause.

# index is an integer (input)
# Returns a string
getCacheRoot( index )

Returns the Nth cache root (indexing begins at 0). Cache roots are set by calling AddCacheRoot one or more times.

# url_or_htmlFilepath is a string (input)
# Returns a string
getEML( url_or_htmlFilepath )

Creates EML from a web page or HTML file, and returns the EML (MIME) message data as a string.

# url_or_htmlFilepath is a string (input)
# Returns a string
getMHT( url_or_htmlFilepath )

Creates MHT from a web page or local HTML file, and returns the MHT (MIME) message data as a string

# htmlText is a string (input)
# Returns a string
htmlToEML( htmlText )

Creates an in-memory EML string from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the EML string that is returned.

Returns True for success, False for failure.

# htmlText is a string (input)
# Returns a string
htmlToMHT( htmlText )

Creates an in-memory MHT web archive from an in-memory HTML string. All external images and style sheets are downloaded and embedded in the MHT string.

# Returns a string
lastErrorHtml( )

Error information in HTML format for the last method called.

# Returns a string
lastErrorText( )

Error information in plain-text format for the last method called.

# Returns a string
lastErrorXml( )

Error information in XML format for the last method called.

# Returns a string
proxy( )

(Optional) A proxy host:port if a proxy is necessary to access the Internet. The proxy string should be formatted as "hostname:port", such as "www.chilkatsoft.com:100".

# Returns a string
proxyLogin( )

If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy login.

# Returns a string
proxyPassword( )

If an HTTP proxy is used and it requires authentication, this property specifies the HTTP proxy password.

# Returns a string
version( )

The version of the component, such as "1.0.0"

# Returns a string
webSiteLogin( )

(Optional) Specifies the login if a a Web page is accessed that requires a login

# Returns a string
webSitePassword( )

Optional) Specifies the password if a a Web page is accessed that requires a login and password