Re: Access to attachment from Mailet
Hi Carl, Yes, it is possible to process a mail attachment from within a mailet. For example, in your matcher, you can check if your message content is an instance of MimeMultipart (assuming the incoming email is multipart MIME encoded), and use the javax.mail.internet.MimeBodyPart to check the type of attachment (using its getContentType()). Then in your mailet, you can do a similar thing and process the attachment as desired. Example code for matcher: public Collection match(Mail mail) throws MessagingException { if(mail.getMessage().getContent() instanceof MimeMultipart) { MimeMultipart multipart = (MimeMultipart) mail.getMessage().getContent(); // extract the MimeBodyParts and check for content type if required. } // if your desired condition is satisfied return mail.getRecipients(); } Hope this helps. Cheers, Sandeep -- http://sandeep.weblogs.us/ Carl Vorster wrote: Hi, Is it possible to access/process a mail attachment from a mailet, I can't seem to find anything to point me in the right direction. Thanks in advance Carl - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Access to attachment from Mailet
Carl, Here is some code from the service() routine of a mailet I use to grab jpg's from attachments: // Loop through the attachments // // Have a look at: // http://java.sun.com/developer/onlineTraining/JavaMail/contents.#GettingAttachments // for some tips on saving attachements. // try { MimeMessage msg = (MimeMessage) mail.getMessage(); Multipart mp = (Multipart) msg.getContent(); boolean imageFound = false; for (int j = 0, n = mp.getCount(); j n; j++) { Part part = mp.getBodyPart(j); String disposition = part.getDisposition(); String contentType = part.getContentType(); log(Content Type = + contentType + Disposition = + disposition); if (contentType.startsWith(image/jpeg)) { imageFound = true; saveImage(user, part); } } if (imageFound) { sendImageReceived(recipient, sender, user); } else { sendImageNotReceived(recipient, sender, user); } } catch (Exception e) { log(Error: , e); } Hope this helps. -- Bud Carl Vorster wrote: Hi, Is it possible to access/process a mail attachment from a mailet, I can't seem to find anything to point me in the right direction. Thanks in advance Carl - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Access to attachment from Mailet
I notice the link in the code is bad. It needs a html after the dot: http://java.sun.com/developer/onlineTraining/JavaMail/contents.html#GettingAttachments Bud Bach wrote: Carl, Here is some code from the service() routine of a mailet I use to grab jpg's from attachments: // Loop through the attachments // // Have a look at: // http://java.sun.com/developer/onlineTraining/JavaMail/contents.#GettingAttachments // for some tips on saving attachements. // try { MimeMessage msg = (MimeMessage) mail.getMessage(); Multipart mp = (Multipart) msg.getContent(); boolean imageFound = false; for (int j = 0, n = mp.getCount(); j n; j++) { Part part = mp.getBodyPart(j); String disposition = part.getDisposition(); String contentType = part.getContentType(); log(Content Type = + contentType + Disposition = + disposition); if (contentType.startsWith(image/jpeg)) { imageFound = true; saveImage(user, part); } } if (imageFound) { sendImageReceived(recipient, sender, user); } else { sendImageNotReceived(recipient, sender, user); } } catch (Exception e) { log(Error: , e); } Hope this helps. -- Bud Carl Vorster wrote: Hi, Is it possible to access/process a mail attachment from a mailet, I can't seem to find anything to point me in the right direction. Thanks in advance Carl - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]