Send work item id as a hyperlink in mail
Hi All,
Scenario is that I have developed sever side plugin to send mail to team members on work item creation. Mail send to all team members successfully.but in mail description I want to work item id as hyperlink instead of separate work item hyperlink
Is it possible ?please provide suggestions on same
Clm server 6.0.5
One answer
You'll need to set the header "Content-type" to "text/html", this would then allow you to use the normal HTML hyperlink <a> tags for links (and other formatting such as bold, etc.). For non-html emails, you could just stick the URL at the end in brackets. ex: "Work Item 1234 (<url>)"
To use HTML in emails you need to create a javax.mail.internet.MimeBodyPart and add this to a javax.mail.internet.MimeMultipart.
See the following code:
IMailerService mailer = getMailerService();
MimeBodyPart plainBody= new MimeBodyPart();
plainBody.setText(getPlainTextContent(), UTF_8);
MimeBodyPart htmlBody = new MimeBodyPart();
htmlBody.setText(getHtmlContent(), UTF_8);
htmlBody.setHeader("Content-type", "text/html; charset=" + UTF_8);
MimeMultipart multipart= new MimeMultipart("");
multipart.addBodyPart(plainBody);
multipart.addBodyPart(htmlBody);
mailer.sendMultipartMail(mailer.getDefaultSender(), getEmailAddress(), "My Email Subject", multipart, null);
Comments
What is the type of message? Can I pass text on there? And for Multipart IMailerServer is required?or can I use mailService.sendMultipartMail() ?I am bit confusing
Please provide the suggestions on same
Thank you
By "text" do you mean a String? If so, yes it does.
You have to use: mailerService .sendMultipartMail(...)
Here is a simpler version which I think answers the questions.
IMailerService mailerService = getMailerService();
MimeBodyPart htmlBody= new MimeBodyPart();
htmlBody.setText("This is my email content. This is in <b>bold</b>", UTF_8);
htmlBody.setHeader("Content-type", "text/html; charset=" + UTF_8);
MimeMultipart multipart = new MimeMultipart("");
multipart.addBodyPart(htmlBody);
mailerService .sendMultipartMail(mailerService .getDefaultSender(), getEmailAddress(), "My Email Subject", multipart, null);