At one point I thought I had this but alas not entirely. I'm working on a calendaring server which serves a fairly large community and need to be able to email calendaring requests out across clients. When I send out a few (say two or three) invitations, then the headers and buttons are seen in MS Outlook but if I send 10 or more at the same time, the buttons disappear. I've threaded my mailer to allow the applications to be functional whilst sending out requests but the body of the email is built in a buildMail callable();
public buildMail(Session sess, Calendar cal, String from, String to, String subject, Transport tr) {
this.sess = sess;
this.cal = cal;
this.from = from;
this.to = to;
this.members = members;
this.subject = subject;
this.tr = tr;
}
public MimeMessage call() {
try {
msg = new MimeMessage(sess);
msg.addHeaderLine("text/calendar;method=REQUEST;charset=UTF-8");
msg.setFrom(new InternetAddress(from));
msg.setRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(to));
msg.setSubject(subject);
msg.setSentDate(new Date());
CalendarOutputter co = new CalendarOutputter(false);
Multipart multipart = new MimeMultipart();
MimeBodyPart messageBodyPart = new MimeBodyPart();
Writer wtr = new StringWriter();
co.output(cal, wtr);
String content = wtr.toString();
messageBodyPart.setContent(content, "text/calendar;method=REQUEST;charset=UTF-8");
multipart.addBodyPart(messageBodyPart);
MimeBodyPart textBodyPart = new MimeBodyPart();
String textBody = "This email is a scheduling event from " + from;
textBodyPart.setContent(textBody, "text/plain");
multipart.addBodyPart(textBodyPart);
msg.setContent(multipart);
tr.connect();
tr.sendMessage(msg, msg.getRecipients(javax.mail.Message.RecipientType.TO));
tr.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}//end run
The handlers for the MimeTypes are set in the main bit of the application before the thread
// add handlers for main MIME types
MailcapCommandMap mc = (MailcapCommandMap)CommandMap.getDefaultCommandMap();
mc.addMailcap("text/html;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("text/xml;; x-java-content-handler=com.sun.mail.handlers.text_xml");
mc.addMailcap("text/plain;; x-java-content-handler=com.sun.mail.handlers.text_plain");
mc.addMailcap("text/calendar;; x-java-content-handler=com.sun.mail.handlers.text_html");
mc.addMailcap("multipart/*;; x-java-content-handler=com.sun.mail.handlers.multipart_mixed");
mc.addMailcap("message/rfc822;; x-java-content-handler=com.sun.mail.handlers.message_rfc822");
CommandMap.setDefaultCommandMap(mc);
As far as I can see, I've set the correct headers in addHeaderline but I get:
From: foo
To: bar
Message-ID: <30219775.51234947377808.JavaMail.SYSTEM@server>
Subject: Do I work across a group?
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----=_Part_1_5048333.1234947377464"
Return-Path: foo
------=_Part_1_5048333.1234947377464
Content-Type: text/calendar;method=REQUEST;charset=UTF-8
Content-Transfer-Encoding: 7bit
------=_Part_1_5048333.1234947377464
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
------=_Part_1_5048333.1234947377464--
and no buttons.
Do I need to explicitly add the .ics file as an attachment to force them? I'd be grateful for any pointers as this is slowly driving me nuts and I'm sure it is something very simple that I've overlooked. Thanks.