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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Html table in Email body

(0) ShareShare
ReportReport
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

I have the same question (0)
  • Verified answer
    Marcellus Profile Picture
    2,735 on at

    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

  • Verified answer
    Marcellus Profile Picture
    2,735 on at

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

  • MedInfoTech Profile Picture
    1,392 on at

    Thank you very much Marcell that was very helpful :)

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans