tags:

views:

619

answers:

0

I'm currently writing a mail programme using JavaMail 1.4 to send out scheduling invitations to a variety of platforms including Outlook, which is where I run into an issue. I can send out one or two invitations and the Accept/Decline buttons show up but if I send out more (which I need to) then the buttons do not appear - so I assume that the text/calendar header is not being read by Outlook, although from the size of the email (c.7-13k as opposed to 1-2k for a working one), the information is being supplied and instead it displays in plain html or plain text.

msg.addHeaderLine("text/calendar;method=REQUEST;charset=\"us-ascii\"");

CalendarOutputter co = new CalendarOutputter(false);
Multipart multipart = new MimeMultipart();

//added in to prevent spam filters thinking this is spam due to no text body. 
MimeBodyPart textBodyPart = new MimeBodyPart();
String textBody = "This email is a scheduling event from " + from;
textBodyPart.setText(textBody);
multipart.addBodyPart(textBodyPart);

//set the calendar as a string inside body of email
MimeBodyPart messageBodyPart = new MimeBodyPart();
Writer wtr =  new StringWriter();
co.output(cal, wtr);
String content = wtr.toString();
messageBodyPart.setContent(content, "text/calendar;charset=\"us-ascii\";  method=REQUEST");
multipart.addBodyPart(messageBodyPart);

//set the calendar as an ics file attachment
MimeBodyPart fileBodyPart = new MimeBodyPart();        
fileBodyPart.setDataHandler(new DataHandler(content, "text/calendar;charset=\"us-ascii\";method=REQUEST"));
fileBodyPart.setFileName("jiscmail.ics");
multipart.addBodyPart(fileBodyPart);

//chunk it all together into one email
msg.setContent(multipart);

Does any one have an idea as to how to ensure that the calendar headers are read for each message sent out? MTIA.