Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How can I display email body in bold letters

 Hello,

 I am writing a plugin for work item save operation which is responsible for sending email to owner of task if certain conditions are met. I have successfully written plugin and tested it on my jetty plugin test environment setup. I am using below method to send email
IMailerService mailService = getService(IMailerService.class);
mailService.sendMail(mailService.getDefaultSender(), mailAddress, emailSubject, emailBody, "");

"emailBody" is string variable, content of emailBody variable are displayed in mail body when user receives email. 
Our users have demanded to make certain part of mail body in bold letters, I have been looking searching on how can I make content of string appear as bold letter in email body, one of the approach was
String emailBody  = "<b> this is mail body </b>"
But instead of displaying text in bold letters (like this - this is mail body) it is displaying entire text (i.e. <b> this is mail body) in plain letters.
Is there any way we can make content of email body in bold format?

0 votes



3 answers

Permanent link

This seems to be a client problem and not a server or API problem. The client interprets the mail as a string and not as an HTML.

0 votes


Permanent link
You are using the wrong API.
You need to create a MimeBodyPart and set the Content-type = text/html header, and then use the API that accepts a MimeMultipart.
See the following code:

IMailerService mailservice = getMailerService();

MimeBodyPart plainBody= new MimeBodyPart();
plainBody.setText(getPlainContent(), UTF_8);

MimeBodyPart htmlBody= new MimeBodyPart();
htmlBody.setText(getHtmlContent(), 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(mailservice .getDefaultSender(), getEmailAddress(), "My email subject", multipart, null);

0 votes

Comments
Hi David
I have tried your above mentions scenario but i am getting
Unable to save work item.javax.mail.BodyPart. error on save work item

Can you provide more of the stack trace, there's not enough information there to tell what's going wrong.


Permanent link

    MimeBodyPart plainBody = new MimeBodyPart();
        plainBody.setText("test", "UTF_8");

        MimeBodyPart htmlBody= new MimeBodyPart();
        htmlBody.setText("<b>test<\b>", "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);
    
    //
        String emailSubject = "Work item " + workItemID + " filed against " + categoryName + " in project area " + projectAreaName + " needs your attention";
        
        
        for(ITeamAreaHandle teamAreaHandle : teamAreaHandles)
        {
            ITeamArea teamArea = (ITeamArea)itemService.fetchItem(teamAreaHandle, IRepositoryItemService.COMPLETE);
            IContributorHandle[] memberHandles = teamArea.getMembers();
            if(memberHandles.length > 0)
            {
                for(IContributorHandle memberHandle : memberHandles)
                {
                    IContributor teamMember= (IContributor)itemService.fetchItem(memberHandle, IRepositoryItemService.COMPLETE);
                    String mailAddress = teamMember.getEmailAddress();                    
                    //send mail to user
                    //mailService.sendMail(mailService.getDefaultSender(), mailAddress, emailSubject, emailBody, "");
                    
                    //Using Multi-part Service here
                    //mailService.sendMultipartMail(mailService.getDefaultSender(), mailAddress,"test", mp, null);
                    mailService.sendMultipartMail(mailService.getDefaultSender(), mailAddress, emailSubject, multipart,"");

                }
          }

   }

I wrote  this code but its giving me error as mentioned above
please correct me

0 votes

Comments

please give me a suggestions on same

We're still going to need the exception stack trace.
There's not enough information in the statement of
"Unable to save work item.javax.mail.BodyPart".

hi David I am unable o get stack trace data, I am stuck in to send html mail,can you please provide sample example related to it

The code provided in my comment was the sample example, I do not know what other code to provide other than that. Hopefully some other readers might be able to help out here.

Why can't you get the stack trace? It should be either in the server log or client log somewhere. Are you able to debug the issue to see what's happening?

Also, is that really the title that is given for the error? It's not even a grammatically correct sentence so I'm not sure how to understand it: "Unable to save work item.javax.mail.BodyPart"

hi Devid, When I add above mentioned cod then I unable to debug the code ,I am unable to trigger code

Did you remember to add the appropriate imports?
Imports at the top of the java file, and updated 'requiredService' in the plugin.xml?

Thank you Devid for quick response, now code is working fine.

showing 5 of 7 show 2 more comments

Your answer

Register or log in 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.

Search context
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
Question details
× 10,937
× 7,495
× 369
× 70

Question asked: Aug 12 '18, 4:31 a.m.

Question was seen: 8,132 times

Last updated: Sep 11 '18, 2:36 a.m.

Confirmation Cancel Confirm