HTML formatted email with tSendMail

One Star

HTML formatted email with tSendMail

(TIS Version 3.1.4 - Java project)
I spent a couple of hours trying to figure out how to send HTML formatted e-mails with the tSendMail component. I have attached a screenshot of how I was configuring the component. As you can see, I was using the "Other headers" to specify a "Content-Type" of text/html. However, all I got when I received the email was plain text.
When I inspected the generated Java code, I saw that the headers were being attached to the MimeMessage, but that later the MimeMessage content was being set to the MimeMultiPart object. I believe the MimeMultiPart is overriding the "other headers" I specified in the component.
So I experimented with the component, and moved the code that sets the headers specified in the component configuration, assigning it to the MimeBodyPart associated to the text part of the email (mbpText_tSendMail_1), instead of applying the headers to the overall MimeMessage (msg_tSendMail_1). This produced the desired effect, as my e-mail was now sent as HTML and was formatted as I specified in the body.
This seems to be a bug, but maybe there is a different way to configure the component that I don't understand? It seems strange to me that no one has ever ran into this before, so maybe there is a differrent way to do it?. Regardless, below is an excerpt of the component showing the modifications I made to make it work as I wanted it:

javax.mail.Multipart mp_<%=cid %> = new javax.mail.internet.MimeMultipart();
javax.mail.internet.MimeBodyPart mbpText_<%=cid %> = new javax.mail.internet.MimeBodyPart();
mbpText_<%=cid %>.setText(message_<%=cid %>);
-- START OF CODE CHANGE: (This is the code that associates the "other" header to the MimeBodyPart)
for (int i_<%=cid %> = 0; i_<%=cid %> < headers_<%=cid %>.size(); i_<%=cid %>++) {
java.util.Map<String, String> header_<%=cid %> = headers_<%=cid %>.get(i_<%=cid %>);
mbpText_<%=cid %>.setHeader(header_<%=cid %>.get("KEY"), header_<%=cid %>.get("VALUE"));
}
-- END CODE CHANGE
mp_<%=cid %>.addBodyPart(mbpText_<%=cid %>);

Note: I also removed the "for loop" that was assigning the headers to the MimeMessage (msg_tSendMail_1)
Thanks in advance,
Andy
Community Manager

Re: HTML formatted email with tSendMail

Hello guy
Thanks for your info, I have reported a 10020.
Best regards
shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Employee

Re: HTML formatted email with tSendMail

One Star

Re: HTML formatted email with tSendMail

ytao,
You mentioned in the bug tracker that I can set the properties in the advanced tab? Is this something only available in 3.2? I am currently using 3.1.4 and the only thing I see in the advanced tab are options for tStatCatcher stats (see uploaded image).
You say this is a duplicate of the other ticket, but I'd like to see an example of how this is done if you say it is already fixed. All I can see is that the data in the "Other headers" is ignored because the multiple part object overrides it.
Have you tried to make it work yourself? Can you send an HTML formatted email?
Employee

Re: HTML formatted email with tSendMail

in 3.1.4, does not includ this feature, you can download files from:
http://www.talendforge.org/svn/tos/trunk/org.talend.designer.components.localprovider/components/tSe...
then replace all same files on your TIS platform.
thx for your advice