01: package org.bouncycastle.mail.smime.examples;
02:
03: import java.io.FileOutputStream;
04: import java.util.Properties;
05:
06: import javax.mail.Address;
07: import javax.mail.Message;
08: import javax.mail.Session;
09: import javax.mail.internet.InternetAddress;
10: import javax.mail.internet.MimeBodyPart;
11: import javax.mail.internet.MimeMessage;
12:
13: import org.bouncycastle.mail.smime.SMIMECompressedGenerator;
14:
15: /**
16: * a simple example that creates a single compressed mail message.
17: */
18: public class CreateCompressedMail {
19: public static void main(String args[]) throws Exception {
20: //
21: // create the generator for creating an smime/compressed message
22: //
23: SMIMECompressedGenerator gen = new SMIMECompressedGenerator();
24:
25: //
26: // create the base for our message
27: //
28: MimeBodyPart msg = new MimeBodyPart();
29:
30: msg.setText("Hello world!");
31:
32: MimeBodyPart mp = gen.generate(msg,
33: SMIMECompressedGenerator.ZLIB);
34:
35: //
36: // Get a Session object and create the mail message
37: //
38: Properties props = System.getProperties();
39: Session session = Session.getDefaultInstance(props, null);
40:
41: Address fromUser = new InternetAddress(
42: "\"Eric H. Echidna\"<eric@bouncycastle.org>");
43: Address toUser = new InternetAddress("example@bouncycastle.org");
44:
45: MimeMessage body = new MimeMessage(session);
46: body.setFrom(fromUser);
47: body.setRecipient(Message.RecipientType.TO, toUser);
48: body.setSubject("example compressed message");
49: body.setContent(mp.getContent(), mp.getContentType());
50: body.saveChanges();
51:
52: body.writeTo(new FileOutputStream("compressed.message"));
53: }
54: }
|