Programming Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

C Examples

Bounced Mail
Bz2
Certificates/Keys
Charset
CSV
Diffie-Hellman
DSA
Email Object
Encryption
FileAccess
FTP
HTML-to-XML
HTTP
IMAP
MHT / HTML Email
MIME
POP3
RSA
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
Zip


 

 

 

 

 

 

 

 

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 C/C++ Libraries for VC++ 9.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 8.0 / Win32

Download Chilkat C/C++ 64-bit Libraries for VC++ 8.0 / x64

Download Chilkat Visual Studio 2005 C/C++ Libs for Windows Mobile, Pocket PC, SmartPhone, WinCE

Download Chilkat C/C++ Libraries for VC++ 7.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0 / Win32

Download Chilkat C/C++ Libraries for VC++ 6.0, Win 95/98/NT4 Compatible

#include <C_CkMailMan.h>
#include <C_CkMht.h>
#include <C_CkEmail.h>
#include <C_CkHtmlToText.h>

void ChilkatSample(void)
    {
    HCkMailMan mailman;
    HCkMht mht;
    BOOL success;
    HCkEmail email;
    HCkHtmlToText h2t;
    const char * html;
    const char * plainText;

    //  The mailman object is used for receiving (POP3)
    //  and sending (SMTP) email.
    mailman = CkMailMan_Create();

    //  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 = CkMht_Create();

    //  Any string argument automatically begins the 30-day trial.

    success = CkMailMan_UnlockComponent(mailman,"30-day trial");
    if (success != TRUE) {
        printf("MailMan component unlock failed\n");
        return;
    }

    success = CkMht_UnlockComponent(mht,"30-day trial");
    if (success != TRUE) {
        printf("Mht component unlock failed\n");
        return;
    }

    CkMht_putUseCids(mht,TRUE);
    email = CkMht_GetEmail(mht,"http://www.bonairefishing.com/");
    if (email == 0 ) {
        printf("%s\n",CkMht_lastErrorText(mht));
        return;
    }

    CkEmail_putSubject(email,"Test HTML/plain-text email");

    CkEmail_AddTo(email,"Chilkat Support","support@chilkatsoft.com");
    CkEmail_putFrom(email,"admin@chilkatsoft.com");

    h2t = CkHtmlToText_Create();
    success = CkHtmlToText_UnlockComponent(h2t,"Anything for 30-day trial");
    if (success != TRUE) {
        printf("%s\n",CkHtmlToText_lastErrorText(h2t));
        return;
    }

    //  Get the email's HTML body.

    html = CkEmail_getHtmlBody(email);

    //  Convert it to plain text:

    plainText = CkHtmlToText_toText(h2t,html);

    //  Add a plain-text alternative to the email:
    CkEmail_AddPlainTextAlternativeBody(email,plainText);

    CkMailMan_putSmtpHost(mailman,"mail.chilkatsoft.com");
    CkMailMan_putSmtpUsername(mailman,"admin@chilkatsoft.com");
    CkMailMan_putSmtpPassword(mailman,"*myPassword5*");

    success = CkMailMan_SendEmail(mailman,email);
    if (success != TRUE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        return;
    }

    CkEmail_Dispose(email);

    printf("HTML/plain-text Email Sent!\n");

    CkMailMan_Dispose(mailman);
    CkMht_Dispose(mht);
    CkHtmlToText_Dispose(h2t);

    }

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

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