Java Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

Java Examples

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

More Examples...
Amazon S3
Email Object
DKIM / DomainKey
NTLM
FileAccess
RSS
Atom
String
Byte Array
Self-Extractor
Service
PPMD
Deflate
DH Key Exchange
DSA
Bzip2
LZW

 

 

 

 

 

 

 

Zip Email Attachments

 Chilkat Java Library Downloads for Windows, Linux, and MAC OS X

The Chilkat email component provides the ability to convert attachments within an email to a single .zip attachment. This example program demonstrates the email attachment zipping capability.

// Chilkat Java Example Program
	
import com.chilkatsoft.CkMailMan;
import com.chilkatsoft.CkEmail;
import com.chilkatsoft.CkString;

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

  // Sending email attachments in a .zip
  public static void main(String argv[]) 
  {
    CkMailMan mailman = new CkMailMan();
    mailman.UnlockComponent("anything for 30-day trial");
    
    // Set your SMTP server's hostname
    mailman.put_SmtpHost("smtp.comcast.net");
    
    // If your SMTP server requires a login, set username/password
    //mailman.put_SmtpUsername("myUsername");
    //mailman.put_SmtpPassword("myPassword");
    
    // Create a simple email
    CkEmail email = new CkEmail();
    email.put_Subject("Sending mail from Java");
    email.put_Body("This email was sent from a Java program");
    email.put_From("Chilkat Support <support@chilkatsoft.com>");
    // Add a few recipients
    email.AddTo("Matt","matt@chilkatsoft.com");
    email.AddTo("TagTooga","admin@tagtooga.com");
    
    // Add attachments as in the previous example (SendWithAttach.java)
    CkString contentType = new CkString();
    boolean b = email.AddFileAttachment("exampleData/hamlet.xml",contentType);
    email.AddStringAttachment("test1.txt","This string is the content of test1.txt");
    email.AddStringAttachment2("test2.txt","This string is the content of test2.txt","iso-8859-1");
    
    // You could send the email at this point in the code by calling mailman.SendEmail.
    // If you did, your email would have 3 attachments: test1.txt, test2.txt, and hamlet.xml
    // However, you could first call email.ZipAttachments like this:
    email.ZipAttachments("myAttachments.zip");
    
    // myAttachments.zip is the name of the attachment that will appear in the email.
   	// After calling ZipAttachments, your email will contain 1 attachment 
   	// (myAttachments.zip) and within it the recipient will find three files: 
   	// test1.txt, test2.txt, and hamlet.xml.   
    boolean success = mailman.SendEmail(email);
    if (!success)
    {
    	mailman.SaveLastError("lastError.txt");	
    }
    
  }
}






 

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