0
1

Currently i have a problem when send the email with content type is multipart. I don't use Email script to send, i use Java mail to do because i have to add a ICS file content(invitation calendar file) to email header. Actually it can work perfectly if i create a main() in ivy and send it but if i called it by ivy script, it always throw error:

 UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; 
        boundary="----=_Part_22_936261044.1395656648093"
    MessagingException: IOException while sending message
    IvyScriptMethodInvocationException: Error calling method sendMail(net.fortuna.ical4j.model.Calendar) on an object of class ch.ivyteam.ivy.scripting.internal.language.StaticAccess. Reason: javax.mail.MessagingException: IOException while sending message;
      nested exception is:
        javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; 
        boundary="----=_Part_22_936261044.1395656648093"
    IvyScriptRuntimeException: IvyScript Runtime Exception in
        Instruction:
            ch.soreco.customers.xabs.util.CalendarUtil.sendMail()

Below code is used for sending email:

Session session = Session.getInstance(properties, authenticator);
        transport = session.getTransport();
        transport.connect(username, password);

        // register the text/calendar mime type
        MimetypesFileTypeMap mimetypes = (MimetypesFileTypeMap) MimetypesFileTypeMap.getDefaultFileTypeMap();
        mimetypes.addMimeTypes("text/calendar ics ICS");

        //register the handling of text/calendar mime type
        MailcapCommandMap mailcap = (MailcapCommandMap) MailcapCommandMap.getDefaultCommandMap();
        mailcap.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_plain");
        mailcap.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain"); 
        mailcap.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html"); 
        mailcap.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml"); 
        mailcap.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed; x-java-fallback-entry=true"); 
        mailcap.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822"); 
        CommandMap.setDefaultCommandMap(mailcap);

        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress(from));
        message.setSubject(subject);
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
        message.setHeader("X-Mailer", "iQuest-Mailer");

        // Create an alternative Multipart
        Multipart multipart = new MimeMultipart("mixed");

        MimeBodyPart descriptionPart = new MimeBodyPart();
   String content = "simple meeting invitation.";
        descriptionPart.setContent(content, "text/html; charset=utf-8");
        BodyPart messageBodyPart = descriptionPart;
        multipart.addBodyPart(messageBodyPart);

        // Add part two, the calendar
        String calString = "BEGIN:VCALENDAR\n" +
                "PRODID:-//XpertIvy//iCal4j 1.0//XABS\n" +
                "VERSION:2.0\n" +
                "CALSCALE:GREGORIAN\n" +
                "METHOD:PUBLISH\n" +
                "BEGIN:VEVENT\n" +
                "DTSTAMP:20140321T033611Z\n" +
                "DTSTART;VALUE=DATE:20140323\n" +
                "DTEND;VALUE=DATE:20140324\n" +
                "UID:xpert.abs-recurrence-0\n" +
                "ORGANIZER:noreply@soreco.ch\n" +
                "ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=cavoirom@gmail.com:MAILTO:cavoirom@gmail.com\n" +
                "X-MICROSOFT-CDO-BUSYSTATUS:OOF\n" +
                "RRULE:FREQ=WEEKLY;COUNT=2;INTERVAL=1;BYDAY=MO,SU\n" +
                "DESCRIPTION:VINH weekly 21.3\n" +
                "SUMMARY:Fatality: Partner\\, Child\\, Parent\n" +
                "EXDATE:20140322\n" +
                "END:VEVENT\n" +
                "END:VCALENDAR\n";

        BodyPart calendarPart = new MimeBodyPart();
        calendarPart.addHeader("Content-Class", "urn:content-classes:calendarmessage");
        calendarPart.setHeader("Content-ID","calendar_message");
        calendarPart.setContent(calString, "text/calendar; charset=\"utf-8\"; method=REQUEST");
        multipart.addBodyPart(calendarPart);

        //Put the multipart in message 
        message.setContent(multipart);

        Transport.send(message);
        transport.close();

Ivy version: 5.04

Javamail verion: 1.4.4

Anyone can help me?

This question is marked "community wiki".

asked 24.03.2014 at 11:29

trungdv's gravatar image

trungdv
(suspended)
accept rate: 52%

edited 25.03.2014 at 04:00


In order to solve this problem, we will need to do two things:

  • Upgrade java mail libray to 1.4.7 (Ivy has java mail version 1.4.4).
  • Add this line of code to the top of your function

    Thread.currentThread().setContextClassLoader( CalendarUtil.class.getClassLoader() );

It will work as it should.

link

answered 25.03.2014 at 03:58

Tran%20Cuong%20Truc's gravatar image

Tran Cuong Truc
(suspended)
accept rate: 100%

I would make the call look like this: ClassLoader oldContextClassLoader = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(MimeMessage.class.getClassLoader()); // Send Mail } finally { Thread.currentThread().setContextClassLoader(oldContextClassLoader); }

(25.03.2014 at 15:57) Peter Stöckli ♦ Peter%20St%C3%B6ckli's gravatar image
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×78

Asked: 24.03.2014 at 11:29

Seen: 10,182 times

Last updated: 25.03.2014 at 15:57