CreateLargeCompressedMail.javaAPI DocBouncy Castle Crypto API 1.41 (Java 1.5)2025Wed Oct 01 10:55:28 BST 2008org.bouncycastle.mail.smime.examples


public class CreateLargeCompressedMail extends Object
a simple example that creates a single compressed mail message using the large file model.

Fields Summary
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)

        // create the generator for creating an smime/compressed message
        SMIMECompressedGenerator  gen = new SMIMECompressedGenerator();
        // create the base for our message
        MimeBodyPart msg = new MimeBodyPart();

        msg.setDataHandler(new DataHandler(new FileDataSource(new File(args[0]))));
        msg.setHeader("Content-Type", "application/octet-stream");
        msg.setHeader("Content-Transfer-Encoding", "binary");

        MimeBodyPart mp = gen.generate(msg, SMIMECompressedGenerator.ZLIB);

        // Get a Session object and create the mail message
        Properties props = System.getProperties();
        Session session = Session.getDefaultInstance(props, null);

        Address fromUser = new InternetAddress("\"Eric H. Echidna\"<>");
        Address toUser = new InternetAddress("");

        MimeMessage body = new MimeMessage(session);
        body.setRecipient(Message.RecipientType.TO, toUser);
        body.setSubject("example compressed message");
        body.setContent(mp.getContent(), mp.getContentType());

        body.writeTo(new FileOutputStream("compressed.message"));