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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Want to sent mail Using HTML templates also want to replace percentile value in templates like %%CustomerName%% with Customer Name

(1) ShareShare
ReportReport
Posted on by 133

Documentation()

OnRun()

SentMailWithTemplate(CustNo : Code[20])

SMTPSetup.GET;
IF Customer.FINDSET THEN
Customer.TESTFIELD("E-Mail");
IF TemplatesTable.GET(Code) THEN
SMTPMail.CreateMessage('',SMTPSetup."User ID",Customer."E-Mail",'Test1','',TRUE);

SMTPMail.Send;

I have the same question (0)
  • Suggested answer
    Nitin Verma Profile Picture
    21,708 Moderator on at

    Not sure If I understood it correctly, can you share complete your code here.

  • AjayPandey Profile Picture
    133 on at

    Documentation()

    OnRun()

    SentMailWithTemplate(CustNo : Code[20])

    SMTPSetup.GET;

    TemplatesTable.CALCFIELDS(ImportTemp);

    IF TemplatesTable.GET('141') THEN

    Customer.RESET;

    Customer.CALCFIELDS("Balance (LCY)");

    Customer.SETFILTER(Balance,'=%1',0);

    IF Customer.FINDSET THEN

       Customer.CALCFIELDS("Balance (LCY)");

       TemplatesTable.CALCFIELDS(ImportTemp);

     Customer.TESTFIELD("E-Mail");

    SMTPMail.CreateMessage('',SMTPSetup."User ID",Customer."E-Mail",'Test1','',TRUE);

    NotificationBody:=NotificationBody.Replace('%CustomerName%','');

    NotificationBody:=NotificationBody.Replace('%CustomerAddress%','');

    NotificationBody:=NotificationBody.Replace('%Contact No%','');

    NotificationBody:=NotificationBody.Replace('%Email%','');

    SMTPMail.Send;

  • AjayPandey Profile Picture
    133 on at

    HTML Codes for templates

    <!DOCTYPE html>

    <html lang="en" xmlns="www.w3.org/.../xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">

    <head>

       <meta charset="utf-8"> <!-- utf-8 works for most cases -->

       <meta name="viewport" content="width=device-width"> <!-- Forcing initial-scale shouldn't be necessary -->

       <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- Use the latest (edge) version of IE rendering engine -->

       <meta name="x-apple-disable-message-reformatting">  <!-- Disable auto-scale in iOS 10 Mail entirely -->

       <title></title> <!-- The title tag shows in email notifications, like Android 4.4. -->

       <!-- CSS Reset : BEGIN -->

       <style>

           /* What it does: Remove spaces around the email design added by some email clients. */

           /* Beware: It can remove the padding / margin and add a background color to the compose a reply window. */

           html,

    body {

       margin: 0 auto !important;

       padding: 0 !important;

       height: 100% !important;

       width: 100% !important;

       /*background: #E49AE9; */

    }

    /* What it does: Stops email clients resizing small text. */

    * {

       -ms-text-size-adjust: 100%;

       -webkit-text-size-adjust: 100%;

    }

    /* What it does: Centers email on Android 4.4 */

    div[style*="margin: 16px 0"] {

       margin: 0 !important;

    }

    /* What it does: Stops Outlook from adding extra spacing to tables. */

    table,

    td {

       mso-table-lspace: 0pt !important;

       mso-table-rspace: 0pt !important;

    }

    /* What it does: Fixes webkit padding issue. */

    table {

       border-spacing: 0 !important;

       border-collapse: collapse !important;

       table-layout: fixed !important;

       margin: 0 auto !important;

    }

    /* What it does: Uses a better rendering method when resizing images in IE. */

    img {

       -ms-interpolation-mode:bicubic;

    }

    /* What it does: Prevents Windows 10 Mail from underlining links despite inline CSS. Styles for underlined links should be inline. */

    a {

       text-decoration: none;

    }

    /* What it does: A work-around for email clients meddling in triggered links. */

    *[x-apple-data-detectors],  /* iOS */

    .unstyle-auto-detected-links *,

    .aBn {

       border-bottom: 0 !important;

       cursor: default !important;

       color: inherit !important;

       text-decoration: none !important;

       font-size: inherit !important;

       font-family: inherit !important;

       font-weight: inherit !important;

       line-height: inherit !important;

    }

    /* What it does: Prevents Gmail from displaying a download button on large, non-linked images. */

    .a6S {

       display: none !important;

       opacity: 0.01 !important;

    }

    /* What it does: Prevents Gmail from changing the text color in conversation threads. */

    .im {

       color: inherit !important;

    }

    /* If the above doesn't work, add a .g-img class to any image in question. */

    img.g-img + div {

       display: none !important;

    }

    /* What it does: Removes right gutter in Gmail iOS app: github.com/.../89  */

    /* Create one of these media queries for each additional viewport size you'd like to fix */

    /* iPhone 4, 4S, 5, 5S, 5C, and 5SE */

    @media only screen and (min-device-width: 320px) and (max-device-width: 374px) {

       u ~ div .email-container {

           min-width: 320px !important;

       }

    }

    /* iPhone 6, 6S, 7, 8, and X */

    @media only screen and (min-device-width: 375px) and (max-device-width: 413px) {

       u ~ div .email-container {

           min-width: 375px !important;

       }

    }

    /* iPhone 6+, 7+, and 8+ */

    @media only screen and (min-device-width: 414px) {

       u ~ div .email-container {

           min-width: 414px !important;

       }

    }

       </style>

       <!-- CSS Reset : END -->

       <!-- Progressive Enhancements : BEGIN -->

       <style>

       .primary{

    background: #30e3ca;

    }

    .bg_white{

    background: #ffffff;

    }

    .bg_light{

    background: #fafafa;

    }

    .bg_black{

    background: #000000;

    }

    .bg_dark{

    background: rgba(0,0,0,.8);

    }

    .email-section{

    padding:2.5em;

    }

    /*BUTTON*/

    .btn{

    padding: 10px 15px;

    display: inline-block;

    }

    .btn.btn-primary{

    border-radius: 5px;

    background: #30e3ca;

    color: #ffffff;

    }

    .btn.btn-white{

    border-radius: 5px;

    background: #ffffff;

    color: #000000;

    }

    .btn.btn-white-outline{

    border-radius: 5px;

    background: transparent;

    border: 1px solid #fff;

    color: #fff;

    }

    .btn.btn-black-outline{

    border-radius: 0px;

    background: transparent;

    border: 2px solid #000;

    color: #000;

    font-weight: 700;

    }

    h1,h2,h3,h4,h5,h6{

    font-family: 'Lato', sans-serif;

    color: #000000;

    margin-top: 0;

    font-weight: 400;

    }

    body{

    font-family: 'Lato', sans-serif;

    font-weight: 400;

    font-size: 15px;

    line-height: 1.8;

    color: rgba(0,0,0,.4);

    }

    table{

    }

    /*LOGO*/

    .logo h1{

    margin: 0;

    }

    .logo h1 {

    color: #30e3ca;

    font-size: 24px;

    font-weight: 700;

    font-family: 'Lato', sans-serif;

    }

    /*HERO*/

    .hero{

    position: relative;

    z-index: 0;

    }

    .hero .text{

    color: rgba(0,0,0,.3);

    }

    .hero .text h2{

    color: #000;

    font-size: 40px;

    margin-bottom: 0;

    font-weight: 400;

    line-height: 1.4;

    }

    .hero .text h3{

    font-size: 24px;

    font-weight: 300;

    }

    .hero .text h2 span{

    font-weight: 600;

    color: #30e3ca;

    }

    /*HEADING SECTION*/

    .heading-section{

    }

    .heading-section h2{

    color: #000000;

    font-size: 28px;

    margin-top: 0;

    line-height: 1.4;

    font-weight: 400;

    }

    .heading-section .subheading{

    margin-bottom: 20px !important;

    display: inline-block;

    font-size: 13px;

    text-transform: uppercase;

    letter-spacing: 2px;

    color: rgba(0,0,0,.4);

    position: relative;

    }

    .heading-section .subheading::after{

    position: absolute;

    left: 0;

    right: 0;

    bottom: -10px;

    content: '';

    width: 100%;

    height: 2px;

    background: #30e3ca;

    margin: 0 auto;

    }

    .heading-section-white{

    color: rgba(255,255,255,.8);

    }

    .heading-section-white h2{

    font-family:

    line-height: 1;

    padding-bottom: 0;

    }

    .heading-section-white h2{

    color: #ffffff;

    }

    .heading-section-white .subheading{

    margin-bottom: 0;

    display: inline-block;

    font-size: 13px;

    text-transform: uppercase;

    letter-spacing: 2px;

    color: rgba(255,255,255,.4);

    }

    ul.{

    padding: 0;

    }

    social {

    display: inline-block;

    margin-right: 10px;

    }

    /*FOOTER*/

    .footer{

    border-top: 1px solid rgba(0,0,0,.05);

    color: rgba(0,0,0,.5);

    }

    .footer .heading{

    color: #000;

    font-size: 20px;

    }

    .footer {

    margin: 0;

    padding: 0;

    }

    .footer ul {

    list-style: none;

    margin-bottom: 10px;

    }

    .footer  {

    color: rgba(0,0,0,1);

    }

    @media screen and (max-width: 500px) {

    }

       </style>

    </head>

    <body width="100%" style=" margin: 0; padding: 0 !important; mso-line-height-rule: exactly; background-color: #A5F7DF;">

    <center style="width: 100%; " >

       <div style="display: none; font-size: 1px;max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-family: sans-serif; background-color:#FFFFFF">

         â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ â€Œ 

       </div>

       <div style="max-width: 750px; margin: 0 auto;" class="email-container">

        <!-- BEGIN BODY -->

    <table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="margin: auto; max-width: 750px;font-family: sans-serif;background-color:#FFFFFF">

                 <caption><tr style="color:#1BABA4;margin:auto;

    font-size:24px;text-align:center; color: #F90A97;background-color:#A5F7DF"><td>

    <strong ><p>%%CompanyName%% <p></strong></td></tr></caption>

          <tr>

             <td valign="top" class="bg_white" style="padding: 1em 2.5em 0 2.5em;">

              <table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%">

              <tr>

              <td class="logo" style="text-align: center;" colspan="3">

               <h1 style="color:Blue">Sales INVOICE</h1>

             </td>

              </tr>

    <tr><td colspan="3" ><table width="100%" style="

    vertical-align: bottom;">

    <tr ><td style="color:black" ><b><u style="margin:50px">TO</u></b><p>Mr/Mrs.

    %%Customer Name%%<p>

    %%Customer Address%%<p>%%Contact No%%</td>

                             <td dir="rtl" style="padding-top:20px;color:black">%%Date%%<br/>

    %%Email%%      

                            </td>

    </tr>

              </table>

             </td>

         </tr><!-- end tr -->

            <tr style="text-align:Left;"><td colspan="3" style="padding-top:20px;color:black"><b>This is to inform you that your Invoice No is %%InvoiceNo%% and Your Invoice Date is %%Date%% , and Due Date is %%Due Date%%.<br><br>Your Invoice Amount is  <dfn style="background-color:yellow">(%%InvoiceAmount%%).</dfn><p>You are requested to please chek your Balance Amount %%BalanceAmount%%.<p>%%Encrytext%%<br><br>Thank you.<br><br>With Regards,<br><br><br><strong style="font-size:9px"><u>Note</u><br>* This is a system generated mail, please contact to the Company for any discrepancy.

    </b></td></tr>

                   <td valign="top" width="30%" style="padding-top: 20px;">

                     <table role="presentation" cellspacing="0" cellpadding="0" border="0" width="100%">

                       <tr>

                         <td style="text-align: right; padding-left: 10px;">

                          <h3 class="heading">Useful Links</h3>

                          <ul>

    <li><a href="https:/.../" target="_blank">Home</a></li>

                   <li><a href="https:/.../" target="_blank">About</a></li>

                   <li><a href="www.flipkart.com/.../" target="_blank">contact us</a></li>

                 </ul>

                         </td>

                       </tr>

                     </table>

                   </td>

                 </tr>

               </table>

             </td>

           </tr><!-- end: tr -->

           <tr>

             <td class="bg_light" style="text-align: center;">

              <hr>

    <tr><td style="padding-top:3px;text-align:center;">Follow Us On      <a href="www.facebook.com/flipkart" target="_blank" rel="noopener"><img style="border:0; height:19px;width:25px;"src="www.birlaschoolpilani.edu.in/.../a>     <a href="" target="_blank"rel="noopener"><img style="border:0; height:19px; width:25px" src="www.birlaschoolpilani.edu.in/.../a>     <a href=""target="_blank" rel="noopener"><img style="border:0;height:19px;width:25px"src="www.birlaschoolpilani.edu.in/.../ln.png" width="19"border="0"></a>     <a href=""target="_blank"rel="noopener"><img style="border:0; height:19px; width:25px" src="www.birlaschoolpilani.edu.in/.../it.png" width="19" border="0"></a>     <a href="" target="_blank" rel="noopener"><img alt="TTicon" style="border:0; height:19px; width:25px" src="www.birlaschoolpilani.edu.in/.../tt.png" width="19" border="0"></a> </td></tr></td></tr></table>

    </div>

     </center>

    </body>

    </html>

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

News and Announcements

Season of Giving Solutions is Here!

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,585

#2
Khushbu Rajvi. Profile Picture

Khushbu Rajvi. 780 Super User 2025 Season 2

#3
YUN ZHU Profile Picture

YUN ZHU 712 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans