Mime type for zip file
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Troy_Shah
Posted On:   Sunday, May 12, 2002 11:59 PM

I have created a zip file in memory and attached it to a mail message. When I get the message, it comes as a text attachment. I want it to be so that it opens the zip file in winZip. The troubling lines are the last few lines. Thanks for any/all help. props = System.getProperties(); session = Session.getDefaultInstance(props, null); session.setDebug(true); msg = new MimeMessage(session); props.put("mail.smtp.host", "mail.pacbell.net"); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("foo@foo.org", false)); msg.setFrom(new InternetAddress(&quo   More>>

I have created a zip file in memory and attached it to a mail message. When I get the message, it comes as a text attachment. I want it to be so that it opens the zip file in winZip. The troubling lines are the last few lines.


Thanks for any/all help.



props = System.getProperties();


session = Session.getDefaultInstance(props, null);


session.setDebug(true);


msg = new MimeMessage(session);


props.put("mail.smtp.host", "mail.pacbell.net");



msg.setRecipients(Message.RecipientType.TO,


InternetAddress.parse("foo@foo.org", false));


msg.setFrom(new InternetAddress("Troy "));


msg.setSubject("Sent by a test run of SimpleMail");


msg.setText("This is the very first test version of the SimpleMail class.");


msg.setHeader("X-Mailer", "SimpleMail2");


msg.setSentDate(new Date());



byte[] bytearray="Hello!
".getBytes();


FileInputStream fis = new FileInputStream("SimpleMail2.java");


ByteArrayOutputStream baos = new ByteArrayOutputStream();



java.util.zip.ZipOutputStream zout = new

java.util.zip.ZipOutputStream(baos);


zout.putNextEntry(new java.util.zip.ZipEntry("a.java"));


StreamCopier.copy(fis, zout);


zout.closeEntry();


byte[] bytearray2 = baos.toByteArray();



fis.close();


MimeMultipart mmp = new MimeMultipart();


MimeBodyPart mbp = new MimeBodyPart(new InternetHeaders(),


bytearray2);


mbp.setFileName("msg.zip");


mmp.addBodyPart(mbp);

msg.setContent(mmp


//Error when I add this param: ,"application/zip"


//javax.activation.UnsupportedDataTypeException thrown


);


   <<Less
About | Sitemap | Contact