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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Inserting new line in email body

(0) ShareShare
ReportReport
Posted on by 11,633

Hi,

I am using SysEmailSystemTable::sendMail() method to send email. The email template is being used with placeholders which are filled by calling SysEmailMessage::stringExpand method. I have a requirement to show some texts on multiple lines inside email body. The text already has '\n' character in it, but it is not showing multiple lines in email being sent. 

I have searched for different methods for sending email, but couldn't find any method which uses email template with placeholders and able to show multiple lines. I have found that the text in the body needs to be converted to HTML, but not sure how I can do this with the current method.

Does anyone have any clue how can I achieve above requirement?

Thanks,

Baber.

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    First of all, what format do you use for you e-mail template?

  • syed baber Profile Picture
    11,633 on at

    Hi Martin,

    If you are referring to Layout column in email template form, it is set to HTML.

    Thanks,

    Baber.

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    Then use HTML code. White spaces such as line-breaks are suppressed in HTML; you have to use tags like <p> or <br />.

    It seems that your question is not about X++ code after all...

  • syed baber Profile Picture
    11,633 on at

    So I have to use these tags in email template and then only I can get new lines in the email being sent ? When I open email template form, and select HTML tab, I can see the format in HTML, is this enough or I need to modify the template here ?

  • syed baber Profile Picture
    11,633 on at

    Hi Martin,

    I have changed the email sending method to use System.Net.Mail class and called mailMessage.set_IsBodyHtml(true) to set the format as HTML. Before this line, I replaced '\n' with '<br>' tags and now I can see the desired results.

    Thanks,

    Baber.

  • Verified answer
    Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    If you add new lines to HTML, they'll be included in the HTML code, but not rendered to resulting UI. You indeed need HTML tags to change the HTML template.

    Or use the text format; line breaks there work as you're used to.

  • Verified answer
    syed baber Profile Picture
    11,633 on at

    Yes, that is the reason, I explicitly replaced '\n' in error Text with '<br>' tags and now I am getting each Error message on separate line when the email is received.

  • Mraj Profile Picture
    42 on at

    Hi Barber ,

    We are trying to send email report  in AX 2012 . we would like to a have email body with multiple line.

     body =  "<B> Dear Sir/Madam , Please find the attached Purchase order,'\n','\br'  attached purchase order is computer generated copy hence signature not required <B>";

    Kindly advise how to create new lines in email body .

    Thanks

    Raj 

  • Martin Dráb Profile Picture
    239,038 Most Valuable Professional on at

    You can see a verified answer just above your question. Do you have any problem with it?

  • Subramani94 Profile Picture
    19 on at

    I just want to insert multiple data from AX. In Email Body.

    How can i achieve that?

    I created Email Template.

    I am using Sysemailtable::sendEmail() for senting email.

    Thanks in Advance

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans