How to attach a table structure in a mail in Business Central - CloudFronts

How to attach a table structure in a mail in Business Central

Introduction:

In this blog, I want to depict how a table structure can be integrated into an Email in Business Central using the HTML tags.

Pre-Requisites :

  1. Microsoft Dynamics 365 Business Central
  2. HTML

Steps:

  1. Create an Email Structure using the SMTP Mail setup Codeunit and pages. The body that is to be attached to the Mail will be the table structure that will be created using HTML tags.
  2. The HTML tags used are as follows:

<th> : To create the heading for the table

<tr>: To create the rows for the table

<td>: To input the data for the table

Code for the table structure and mail is as follows:

SMTPSetup.CreateMessage('', SMTPMailSetup."User ID", Rec_Contact2."E-Mail", 'Scheduling Report', '', TRUE);
SMTPSetup.AppendBody(MailBody);
SMTPSetup.AppendBody('<br>');
SMTPSetup.AppendBody(UserDetails);
SMTPSetup.AppendBody('<br>');
SMTPSetup.AppendBody('<table border="1">');
SMTPSetup.AppendBody('<tr>');
SMTPSetup.AppendBody('<th>Purchase Conformation</th>');
SMTPSetup.AppendBody('<th>Vendor Name</th>');
SMTPSetup.AppendBody('<th>Vendor Ref:</th>');
SMTPSetup.AppendBody('<th>Product Name</th>');
SMTPSetup.AppendBody('<th>Estimated PU Date</th>');
SMTPSetup.AppendBody('<th>PU Date</th>');
SMTPSetup.AppendBody('<th>PU Time Begin</th>');
SMTPSetup.AppendBody('<th>PU Time End</th>');
SMTPSetup.AppendBody('</tr>');
SMTPSetup.AppendBody('<tr>');
SMTPSetup.AppendBody('<td>' + Format("Blanket PO No.") + '-' + Format("Blanket PO Line No.") + '</td>');
SMTPSetup.AppendBody('<td>' + Format(Name) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(VSO) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(ProductName) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(EstPUDate) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(PUDate) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(PUStartTime) + '</td>');
SMTPSetup.AppendBody('<td>' + Format(PUEndTime) + '</td>');
SMTPSetup.AppendBody('</tr>');
SMTPSetup.AddCC(Rec_UserSetup."E-Mail");
SMTPSetup.Send;

3) The table output looks as follows when the mail is sent:

 

 

 

 

 

 

 

Conclusion:

Thus, using the basic HTML table tags a table structure can be integrated into the Email functionality of Business Central.


Share Story :

SEARCH BLOGS :

FOLLOW CLOUDFRONTS BLOG :


Secured By miniOrange