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

How to set content type to HTML "text/html" when using sendMail in IMailer service while using RTC extensions

I have written custom code using RTC extensions to send emails for different scenarios in my defect workflow.
I want to use the IMailer service sendmail() to do this. Currently I am using native javax mail api to do this.

a) I'm sending emails with custom HTML content.
b) I'm able to use sendMail() of IMailerservice to sendemails also. E.g sendmail line : 
MymailerService.sendMail(sender, toEmail, newsubject, contentStr, "");

I'm having trouble in setting the contentType to HTMl when using sendMail.

any suggestions / help is highly appreciated.

Thank you

0 votes


Accepted answer

Permanent link
See:  https://jazz.net/forum/questions/68412/questions-about-imailerservice

anup Gaur selected this answer as the correct answer

0 votes

Comments
Hi Kevin,
Thanks for that link. That was exactly the code I was looking for.
Thanks a lot.


One other answer

Permanent link
Not an rtc question, really, but....

You need to add headers to the MimeMessage object

            MimeMessage msg = new MimeMessage(session);
            msg.setFrom(new InternetAddress(from));
           
            msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to, false));
            msg.setRecipients(Message.RecipientType.CC, InternetAddress.parse(cc,false));
            msg.setSubject(subject);
            msg.setText(body);
             msg.setHeader("X-Mailer", "JavaMail");
            msg.setHeader("Content-Type", "text/html");
            msg.setSentDate(new Date());
            Transport.send(msg);
 

0 votes

Comments
 Hi Kevin
Thanks for the answer. But this is the code that I'm already using and I'm able to send Emails in HTML format. 
I'm moving my code so as to use the RTC API IMailerService to send emails using the sendEmail() method call. 
Sample code is given below.
IMailerService MymailerService = getService(IMailerService.class);
MailSender sender = MymailerService.getDefaultSender();
if(MymailerService.isMailEnabled()){
MymailerService.sendMail(sender, toEmail, newsubject, mailBodyContent, ""); 
} else {
System.out.println("RTC Mail Service is Not ENABLED!!");
}
I'm migrating my code from native Java code, 
so I can reuse the JTS email settings without having to set SMTP HOST, Sent From etc. 
I was not able to find HTML header or MIME settings in sendMail RTC method.

Well, users are able to elect format of the email sent to them via JTS in their User Profile.  Not sure "registered" users are your target, but that could be why html doesn't come out the back end.

 Yes, thats a good direction to look at. Although I'm not using any existing templates or anything to send the email. The code example given above is pretty much it. I was trying to find a setting like setContentType, setMimeType, or setHeader to HTML type.


Also in the sendMail method, on of the argument is the content. This is the email body which is a string type. Sending HTML tags here also doesn't resolve the issue. Somewhere we need to specify the content type as HTML

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,938
× 457

Question asked: Nov 03 '15, 10:35 a.m.

Question was seen: 5,466 times

Last updated: Nov 03 '15, 3:18 p.m.

Confirmation Cancel Confirm