Java Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Java Examples

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

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

Unreleased...
Bzip2
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 Java Library

import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    //  The mailman object is used for receiving (POP3)
    //  and sending (SMTP) email.
    CkMailMan mailman = new 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.
    CkMht mht = new CkMht();

    //  Any string argument automatically begins the 30-day trial.
    boolean success;
    success = mailman.UnlockComponent("30-day trial");
    if (success != true) {
        System.out.println("MailMan component unlock failed");
        return;
    }

    success = mht.UnlockComponent("30-day trial");
    if (success != true) {
        System.out.println("Mht component unlock failed");
        return;
    }

    CkEmail email;

    mht.put_UseCids(true);
    email = mht.GetEmail("http://www.bonairefishing.com/");
    if (email == null ) {
        System.out.println(mht.lastErrorText());
        return;
    }

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

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

    CkHtmlToText h2t = new CkHtmlToText();
    success = h2t.UnlockComponent("Anything for 30-day trial");
    if (success != true) {
        System.out.println(h2t.lastErrorText());
        return;
    }

    //  Get the email's HTML body.
    String html;
    html = email.getHtmlBody();

    //  Convert it to plain text:
    String plainText;
    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) {
        System.out.println(mailman.lastErrorText());
        return;
    }

    System.out.println("HTML/plain-text Email Sent!");


  }
}

 

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

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