Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics NAV (Archived)

Html table in Email body

Posted on by 1,392

Hello experts,

Please how to create a mail with html table in body something like this :

test 1111 test22222 test3333
aaaa bbb ccccc
xxxx yyyy zzz

 this is my code :

SMTPMailSetup.GET;
 SMTPMail.CreateMessage('MDyanamicsNAV',SMTPMailSetup."User ID",Recp_Email,'Subject','',TRUE);
 SMTPMail.AppendBody('hello,');
 SMTPMail.AppendBody('<br>');
 SMTPMail.AppendBody('<br>');
 SMTPMail.AppendBody('Please verify your mail');
 SMTPMail.AppendBody('<br>');
 SMTPMail.AppendBody('<br>');
 SMTPMail.AppendBody('<table  style="width:100%;border:1px solid black;"><tr><th>test1111</th><th>test22222</th> <th>test3333</th></tr>');
 SETFILTER(Status,'=%1',Status::Approved);
 IF FINDSET THEN BEGIN
   REPEAT
  SMTPMail.AppendBody(<tr><th>'+record.xxx+'</th><th>'+"record.yyy"+'</th><th>'+"record.zzz"+'</th></tr>');
   UNTIL  NEXT = 0;
 END;
 SMTPMail.AppendBody('</table>');
SMTPMail.AppendBody('<hr>');
SMTPMail.AppendBody('Please don't reply'); SMTPMail.Send; MESSAGE('Mail Sent');


*This post is locked for comments

  • MedInfoTech Profile Picture
    MedInfoTech 1,392 on at
    RE: Html table in Email body

    Thank you very much Marcell that was very helpful :)

  • Verified answer
    Marcellus Profile Picture
    Marcellus 2,735 on at
    RE: Html table in Email body

    You can also check this blog post from Saurav Dhyani's blog post: saurav-nav.blogspot.co.uk/.../email-from-nav.html

  • Verified answer
    Marcellus Profile Picture
    Marcellus 2,735 on at
    RE: Html table in Email body

    Hi Medo,

    I created an example for you, I'm doing a loop on the released Sales Orders:

    SMTPMailSetup.GET;
    SMTPMail.CreateMessage('MDynamicsNAV', Recp_Email, Recp_Email, 'Subject', '', TRUE);
    SMTPMail.AppendBody(CreateEmailBody);
    SMTPMail.Send;
    
    MESSAGE('Mail Sent');
    
    LOCAL CreateEmailBody() : Text
    // SalesHeader	Record	Sales Header	
    // EmailBodyText	Text		
    SalesHeader.SETRANGE("Document Type", SalesHeader."Document Type"::Order);
    SalesHeader.SETRANGE(Status, SalesHeader.Status::Released);
    
    EmailBodyText += '<table border="1">';
    EmailBodyText += '<tr>';
    EmailBodyText += STRSUBSTNO('<td>%1</td>', SalesHeader.FIELDCAPTION("No."));
    EmailBodyText += STRSUBSTNO('<td>%1</td>', SalesHeader.FIELDCAPTION("Sell-to Customer Name"));
    EmailBodyText += STRSUBSTNO('<td>%1</td>',SalesHeader.FIELDCAPTION("Document Date"));
    EmailBodyText += '</tr>';
    
    IF SalesHeader.FINDSET THEN
      REPEAT
        EmailBodyText += '<tr>';
        EmailBodyText += STRSUBSTNO('<td>%1</td>', SalesHeader."No.");
        EmailBodyText += STRSUBSTNO('<td>%1</td>', SalesHeader."Sell-to Customer Name");
        EmailBodyText += STRSUBSTNO('<td>%1</td>',SalesHeader."Document Date");
        EmailBodyText += '</tr>';
      UNTIL SalesHeader.NEXT = 0;
    
    EmailBodyText += '</table>';
    
    EXIT(EmailBodyText);
    
    


    The email looks like this:

    3323.Email.png

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans