Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
Convert Email HTML to Plain-Text AlternativeLoads an HTML email from a web page, converts the HTML to a plain-text alternative body, and sends it.
#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.