Chilkat Examples

ChilkatHOMEAndroid™AutoItCC#C++Chilkat2-PythonCkPythonClassic ASPDataFlexDelphi DLLGoJavaNode.jsObjective-CPHP ExtensionPerlPowerBuilderPowerShellPureBasicRubySQL ServerSwiftTclUnicode CUnicode C++VB.NETVBScriptVisual Basic 6.0Visual FoxProXojo Plugin

Classic ASP Examples

Web API Categories

ASN.1
AWS KMS
AWS Misc
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Azure Cloud Storage
Azure Key Vault
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Cert Store
Certificates
Cloud Signature CSC
Code Signing
Compression
DKIM / DomainKey
DNS
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
Microsoft Graph
Misc
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
Secrets
SharePoint
SharePoint Online
Signing in the Cloud
Socket/SSL/TLS
Spider
Stream
Tar Archive
ULID/UUID
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl
uncategorized

 

 

 

Load MHT and Send as Email

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

Load a .MHT file and send it as email.

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
'  The mailman object is used for sending and receiving email.
set mailman = Server.CreateObject("Chilkat_9_5_0.MailMan")

'  Any string argument automatically begins the 30-day trial.
success = mailman.UnlockComponent("30-day trial")
If (success <> 1) Then
    Response.Write Server.HtmlEncode("Component unlock failed") & "<br>"

End If

'  Set the SMTP server.
mailman.SmtpHost = "smtp.comcast.net"

'  Create a new email object
set email = Server.CreateObject("Chilkat_9_5_0.Email")

'  MHT is MIME and therefore can be loaded directly
'  into an email object via the email.LoadEml method.
'  However, if the HTML sub-part of the MIME contains
'  header fields such as this:

'  Content-ID: <BalanceSheet>
'  Content-Disposition: inline;
'  	filename="BalanceSheet"
'  Content-Type: text/html;
'  	name="BalanceSheet";
'  	charset="utf-8"

'  Microsoft Outlook will interpret this as an attached HTML file
'  rather than the HTML body of the email.  Interestingly,
'  Mozilla Thunderbird handles it correctly, but Outlook does not.
'  Google's GMail also handles it correctly.  Yahoo Mail doesn't
'  know what to do and displays nothing -- not even the "attachment".

'  Rather than loading the MHT into the email object, we'll
'  first load it into a Chilkat MIME object and check for
'  these headers.  We want the header fields of the HTML sub-part
'  to look like this:

'  Content-Type: text/html;
'  	charset="utf-8"

'  To do so, we'll remove the Content-ID and Content-Disposition
'  header fields, and the "name" attribute from the
'  Content-Type header.

'  Note: Chilkat MIME is a separate product.  This code
'  would require licenses to both Chilkat Email and Chilkat Mime,
'  or alternatively a Chilkat Bundle license (which includes
'  all Chilkat components).

set mime = Server.CreateObject("Chilkat_9_5_0.Mime")

success = mime.UnlockComponent("Anything for 30-day trial")
If (success <> 1) Then
    Response.Write Server.HtmlEncode("Failed to unlock MIME component") & "<br>"

End If

success = mime.LoadMimeFile("test.mht")
If (success <> 1) Then
    Response.Write Server.HtmlEncode(mime.LastErrorText) & "<br>"

End If

'  Is this a multipart/related?  If so, find the HTML part,
'  which should be the 1st sub-part.
If (mime.IsMultipartRelated() = 1) Then
    '  Find the HTML part.

    n = mime.NumParts

    For i = 0 To n - 1
        Set mimePart = mime.GetPart(i)
        If (mimePart.IsHtml() = 1) Then
            Exit Do
        End If

    Next
    If (Not (mimePart Is Nothing )) Then
        '  Remove these header fields:
        mimePart.SetHeaderField "Content-Disposition",""
        mimePart.SetHeaderField "Content-ID",""
        '  Remove the "name" attribute from the Content-Type header:
        mimePart.Name = ""

    End If

End If

email.SetFromMimeText mime.GetMime()

email.Subject = "This is a test"

email.From = "Chilkat Support <support@chilkatsoft.com>"
email.AddTo "Chilkat Admin","admin@chilkatsoft.com"

success = mailman.SendEmail(email)
If (success <> 1) Then
    Response.Write Server.HtmlEncode(mailman.LastErrorText) & "<br>"
Else
    Response.Write Server.HtmlEncode("Mail Sent!") & "<br>"
End If

%>
</body>
</html>

 

© 2000-2026 Chilkat Software, Inc. All Rights Reserved.