web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Email Template adds multiple html paragraph code when creating an email

(0) ShareShare
ReportReport
Posted on by

Hi everyone,

We're having a formatting problem with the email sent when using an email template. A lot of html paragraphs are added to the message (i.e. <p>), thus ruining the presentation. Anyone has experimented this problem and found a workaround? Same template is working perfectly in 2009. The tampering occurs before the message is stored in the SysOutgoingEmailTable table.

Regards,

Eric

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at
    RE: Email Template adds multiple html paragraph code when creating an email

    Hi baber , did u find the solution for this because i am getting this issue ..

  • Suggested answer
    LiuJie Xu Profile Picture
    90 on at
    RE: Email Template adds multiple html paragraph code when creating an email

    //remove the enter which was created by system
    messageBody = strReplace(messageBody, '\n', '');

    messageBody = SysEmailMessage::stringExpand(messageBody, SysEmailTable::htmlEncodeParameters(_mappings));

    messageBody = strReplace(messageBody, '\n', '<br>');

    Based on the testing, I noticed that, standard AX sytem will add the <br> infront each line after call strReplace

    <BODY><P><FONT size=2 face=Calibri>Hi All,</FONT></P></BODY>

    After call the StrReplace function :

    <br><BODY><P><FONT size=2 face=Calibri>Hi All,</FONT></P></BODY>

    So i try to remove the default enter before expand the mapping value. 

  • Community Member Profile Picture
    on at
    RE: Email Template adds multiple html paragraph code when creating an email

    Maybe you could try the html paragraph separator, i.e. <p>

  • syed baber Profile Picture
    11,633 on at
    RE: Email Template adds multiple html paragraph code when creating an email

    Hi Jonathan,

    I have a requirement to display multiple error messages in the email being sent using defined email template. I am using %errorLog% placehoder in email template and populating it with multiple error message Text. I need to show each error message on separate line. I tried using the below line, but getting all error messages on the same line though I am adding '\n' after each error message:

    messageBody = strReplace(messageBody, '\n', '<br>');

    Any idea how to achieve this requirement or what I am missing here ?

    Thanks,

    Baber.

  • Community Member Profile Picture
    on at
    RE: Email Template adds multiple html paragraph code when creating an email

    Thanks Jonathan for the additional information.

    BTW, I've incorporated customized placeholder in email using the approach you wrote on your website, so thanks for this. Somehow I couldn't comment on your blog entry.

    Eric

  • Suggested answer
    Jonathan  Halland Profile Picture
    11,310 on at
    RE: Email Template adds multiple html paragraph code when creating an email

    HI Eric.

    I don't think alot of people make use of editing the HTML directly, but rather the visual editor with the assumption of new lines actually showing as new lines (this also applies to replaced tags which have no chance of having <br> tags), hence the code change. However I wanted a precise design so I overcame this by using an external editor and then exporting a flattened version into AX each time. For certain applications we also customised the line you mentioned to only be executed under specific conditions.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Email Template adds multiple html paragraph code when creating an email

    Well, I figure it out.

    In the SysEmailTable::sendMail() method, there is this line:

               messageBody = strReplace(messageBody, '\n', '<br>');

    used twice in the code.

    I've compare the sendMail() method with the 2009 version; those lines weren't there. This is obviously a bug. I guess not a lot people are using email templates... or we are lacking one serious update to our installation.

    In the email template, it is not possible to enter the html code and remove line-feed as the editor will reformat the html code to insert them back when the template is saved. Same behavior as it was with 2009. It would make a very unreadable html code anyway if we had to force everything on a single line.

  • Community Member Profile Picture
    on at
    RE: Email Template adds multiple html paragraph code when creating an email

    Hi Uilian, thanks for your reply.

    Important precision, it is not the html <p> code which is being inserted, its the line break <br>, which is added to every line.

    I created a simple email template. It displays correctly in the AX preview or if I open it using a browser:

    <TABLE id=table1 style="BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-TOP-WIDTH: 0px" cellSpacing=0 cellPadding=0 width=600 border=0>

    <TBODY>

    <TR>

    <TD height=70 vAlign=top align=left><FONT face=Arial><A href="server.com/.../&quot;><IMG style="HEIGHT: 101px; WIDTH: 117px" border=0 hspace=0 src="server.com/.../Image.png&quot; width=117 align=left height=101></A></FONT></TD></TR>

    <TR>

    <TD></TD></TR>

    <TR>

    <TD><SPAN style="LETTER-SPACING: 7pt"><FONT color=#6d6e71 size=5 face=Arial>Message from <B>Microsoft Dynamics AX</B></FONT></SPAN></TD></TR></TBODY></TABLE>

    The resulting email come like this, lots of <br> are added:

    <html><HEAD></HEAD>

    <BODY>

    <TABLE id=table1 style="BORDER-RIGHT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-TOP-WIDTH: 0px" cellSpacing=0 cellPadding=0 width=600 border=0>

    <TBODY><BR>

    <TR><BR>

    <TD height=70 vAlign=top align=left><FONT face=Arial><A href="server.com/.../&quot;><IMG style="HEIGHT: 101px; WIDTH: 117px" border=0 hspace=0 src="server.com/.../Image.png&quot; width=117 align=left height=101></A></FONT></TD></TR><BR>

    <TR><BR>

    <TD></TD></TR><BR>

    <TR><BR>

    <TD><SPAN style="LETTER-SPACING: 7pt"><FONT color=#6d6e71 size=5 face=Arial>Message from <B>Microsoft Dynamics AX</B></FONT></SPAN></TD></TR><BR></TBODY><BR></TABLE></BODY></html>

    I have no idea what setting is causing this. We never had any problem with 2009 but 2012 sure likes its line breaks!

    Regards,

    Eric

  • Suggested answer
    Iulian Cordobin Profile Picture
    8,201 on at
    RE: Email Template adds multiple html paragraph code when creating an email

    How did you create your HTML text? Copy paste from another source, or entered with the editor? Maybe you have whitespaces that AX tries to correct. I would look for special characters (like <CR><LF>) with another editor knowing to display them, and remove them.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

#1
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans