Python Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Python Examples

Quick Start
Unicode
Byte Array
Bz2
Certificates
CSV
Email
Encryption
FTP
HTML-to-XML
HTTP
IMAP
MHT
MIME
POP3
RSA
S/MIME
Signatures
Socket / SSL
SFTP
SMTP
Spider
SSH Key
SSH
SSH Tunnel
Tar
HTTP Upload
XML
XMP
Zip

More Examples...
String
Email Object
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA

Unreleased...
Bzip2
LZW
Icon

 

 

 

 

 

 

 

Convert Email HTML to Plain-Text Alternative

Loads an HTML email from a web page, converts the HTML to a plain-text alternative body, and sends it.

Download Chilkat Python Library

import sys
import chilkat

#  The mailman object is used for receiving (POP3)
#  and sending (SMTP) email.
mailman = chilkat.CkMailMan()

#  The MHT component can be used to convert an HTML page
#  from a URL, file, or in-memory HTML into an email
#  with embedded images and style sheets.
mht = chilkat.CkMht()

#  Any string argument automatically begins the 30-day trial.
success = mailman.UnlockComponent("30-day trial")
if (success != True):
    print "MailMan component unlock failed"
    sys.exit()

success = mht.UnlockComponent("30-day trial")
if (success != True):
    print "Mht component unlock failed"
    sys.exit()

mht.put_UseCids(True)
email = mht.GetEmail("http://www.bonairefishing.com/")
if (email == None ):
    print mht.lastErrorText()
    sys.exit()

email.put_Subject("Test HTML/plain-text email")

email.AddTo("Chilkat Support","support@chilkatsoft.com")
email.put_From("admin@chilkatsoft.com")

h2t = chilkat.CkHtmlToText()
success = h2t.UnlockComponent("Anything for 30-day trial")
if (success != True):
    print h2t.lastErrorText()
    sys.exit()

#  Get the email's HTML body.

html = email.getHtmlBody()

#  Convert it to plain text:

plainText = h2t.toText(html)

#  Add a plain-text alternative to the email:
email.AddPlainTextAlternativeBody(plainText)

mailman.put_SmtpHost("mail.chilkatsoft.com")
mailman.put_SmtpUsername("admin@chilkatsoft.com")
mailman.put_SmtpPassword("*myPassword5*")

success = mailman.SendEmail(email)
if (success != True):
    print mailman.lastErrorText()
    sys.exit()

print "HTML/plain-text Email Sent!"


 

Need a specific example? Send a request to support@chilkatsoft.com

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