Ruby Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Ruby
Examples

Quick Start
Ruby Unicode
Ruby Byte Array
Ruby Certs
Ruby Email
Ruby Encryption
Ruby FTP
HTML-to-XML
Ruby HTTP
Ruby IMAP
Ruby MHT
Ruby MIME
Ruby S/MIME
Ruby Signatures
Ruby RSA
Ruby Socket
Ruby Spider
Ruby Tar
Ruby Upload
Ruby XML
Ruby XMP
Ruby Zip

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

Unreleased...
LZW
Bz2
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 Ruby Library

require 'chilkat'

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

#  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.new()

#  Any string argument automatically begins the 30-day trial.
success = mailman.UnlockComponent("30-day trial")
if (success != true)
    print "MailMan component unlock failed" + "\n"
    exit
end

success = mht.UnlockComponent("30-day trial")
if (success != true)
    print "Mht component unlock failed" + "\n"
    exit
end

mht.put_UseCids(true)
email = mht.GetEmail("http://www.bonairefishing.com/")
if (email == nil )
    print mht.lastErrorText() + "\n"
    exit
end

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

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

h2t = Chilkat::CkHtmlToText.new()
success = h2t.UnlockComponent("Anything for 30-day trial")
if (success != true)
    print h2t.lastErrorText() + "\n"
    exit
end

#  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() + "\n"
    exit
end

print "HTML/plain-text Email Sent!" + "\n"


 

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

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