It's all about the answers!

Ask a question

Questions about IMailerService


Sylvain LEQUEUX (2132728) | asked Dec 05 '11, 9:07 a.m.
Hello,

I'm extending TeamConcert V3 (server side) by implementing a precondition on the save workitem operation. My extension needs to send an email so I use IMailerService. Nevertheless, I have 2 questions about it and the content I need to put in my mail.

1/ I'm able to send an email, but is there a way to format it in HTML ? I tried this (which didn't worked) :

IMailerService mailer = getService(IMailerService.class);
mailer.sendMail(mailer.getDefaultSender(), myEmailAddress, "Mail title", "<h1>A header</h1>And the content, "");


2/ I have a reference to my workitem (both in old and new states) and I would like to get a link reference to put it in the mail. Il there a way to do it without building the URI by hands ?

Best Regards,
Sylvain Lequeux

2 answers



permanent link
sam detweiler (12.5k6195201) | answered Dec 05 '11, 9:46 a.m.
the class com.ibm.team.workitem.service.internal.save.notify.ChangeEventMailNotifier

is the code that builds and send the standard RTC change notification messages. Net on the HTML format tho, is YOU format it, and put it into the mime structure to indicate HTML formatted.

you can get the source for the class and others by opening the Plugin perspective view, finding the com.ibm.team.workitem.service plugin, then right mouse button click, Import as Source Project.

the code that does the email processing and calls the mailer is in SendIndividualMails


if (recipient.prefersHtmlFormat() && htmlContent.length() > 0) {
MimeBodyPart plainBody= new MimeBodyPart();
plainBody.setText(hisContent, UTF_8);

MimeBodyPart htmlBody= new MimeBodyPart();
htmlBody.setText(hisHtmlContent, UTF_8);
htmlBody.setHeader("Content-type", "text/html; charset=" + UTF_8); //$NON-NLS-1$ //$NON-NLS-2$

MimeMultipart multipart= new MimeMultipart("alternative"); //$NON-NLS-1$
multipart.addBodyPart(plainBody);
multipart.addBodyPart(htmlBody);

mailer.sendMultipartMail(mailer.getDefaultSender(), recipient.getEmailAddress(), hisSubject, multipart, null);
} else {
mailer.sendMail(mailer.getDefaultSender(), recipient.getEmailAddress(), hisSubject, hisContent, null);
}


this class also builds the links and other workitem changes, so some code there would help u solve the URI question I think..

Sam

permanent link
Sylvain LEQUEUX (2132728) | answered Dec 06 '11, 7:15 a.m.
Hi,

Thank you very much Sam. That was exactly what I was looking for.

Sylvain

Comments
Sachin Nairy commented Aug 29 '13, 8:08 a.m.

Hi Sylvain,

If possible, can you share this code, we are looking for the same feature.

Regards

Sachin Nairy


Sylvain LEQUEUX commented Aug 29 '13, 8:51 a.m.

Hello,

Sam answered my first question with the code I used.
If you need something more, could you clarify what part of code is missing for you ?

Regards,
Sylvain

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.