Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      June 2, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      June 2, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      June 2, 2025

      How To Prevent WordPress SQL Injection Attacks

      June 2, 2025

      How Red Hat just quietly, radically transformed enterprise server Linux

      June 2, 2025

      OpenAI wants ChatGPT to be your ‘super assistant’ – what that means

      June 2, 2025

      The best Linux VPNs of 2025: Expert tested and reviewed

      June 2, 2025

      One of my favorite gaming PCs is 60% off right now

      June 2, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      `document.currentScript` is more useful than I thought.

      June 2, 2025
      Recent

      `document.currentScript` is more useful than I thought.

      June 2, 2025

      Adobe Sensei and GenAI in Practice for Enterprise CMS

      June 2, 2025

      Over The Air Updates for React Native Apps

      June 2, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025
      Recent

      You can now open ChatGPT on Windows 11 with Win+C (if you change the Settings)

      June 2, 2025

      Microsoft says Copilot can use location to change Outlook’s UI on Android

      June 2, 2025

      TempoMail — Command Line Temporary Email in Linux

      June 2, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Optimizely Configured Commerce – Email Administration And More

    Optimizely Configured Commerce – Email Administration And More

    January 3, 2025

    Optimizely Configured Commerce provides a unique way of managing emails. This allows administrators to configure and manage the email templates and settings used for automated email communications with users. This feature is essential for ensuring consistent branding, and operational efficiency in a B2B e-commerce environment. And most importantly, those emails are setup automatically and should not require many updates.

    However, in some scenarios, you might need more customizations when working with emails. This article will provide more insights about Optimizely Configured Commerce’s Emails that have not been covered in the documentation. You will get some ideas on how to deeply customize the Email Templates and also, send emails using the B2B framework from Optimizely.

    Prerequisites

    Before jumping into customization, you need to have fundamental understandings about Email Administration in Configured Commerce.

    • This will help you know more about the process flow for how emails are sent: https://docs.developers.optimizely.com/configured-commerce/v1.5.45-b2b-sdk/docs/defining-working-with-and-troubleshooting-email-lists-and-templates
    • You also need to be able to work with Email Templates in admin console effectively: https://docs.developers.optimizely.com/configured-commerce/v1.5.45-b2b-sdk/docs/creating-and-editing-email-templates

    How to send email with Optimizely Configured Commerce

    In Optimizely Configured Commerce, emails are sent automatically when a certain event occurs on a webpage (for example, order confirmation email is sent when submitting an order). However, some actions are not associated with sending mails. If you want to do that, like sending a notification email to the new registrant, you have to put some code inside your custom handlers, or Web API Controllers. Using .NET SmtpClient is a good choice, but in the scope of this article, I would suggest utilizing the EmailService inside the B2B framework that we’re using. The reason is you can benefit from the Email Administration feature that is integrated to Configured Commerce, from managing email templates to monitoring the email message logs, etc. Every mail sending through the EmailService will be kept track of inside this screen:

    Opti B2b Email Logs

    As being said, here’s how you can send the email any time with B2B Email Service (along with explanation):

    // getting email template from IEmailTemplateUtilities (you need to inject this interface in your controller)
    var emailTemplate = emailTemplateUtilities.GetOrCreateByName("MyCustomEmailTemplate");
    
    // retrieving the content manager from the email template
    var emailTemplateContentManager = emailTemplate.ContentManager;
    
    // using IContentManagerUtilities to get the current version of the email body (you also need to inject this interface in your controller)
    var htmlBody = contentManagerUtilities.CurrentContent(emailTemplateContentManager).Html;
    
    // now create the email model to store the dynamic data. It's basically an ExpandoObject
    dynamic emailModel = new ExpandoObject();
    emailModel.Name = "John Doe";
    
    // Parsing the template. For example, the placeholder [[Model.Name]] in the html body will be replaced with the actual data of emailModel, which is "John Doe".
    // You need to inject the IEmailService before using it
    string strEmailBody = emailService.Value.ParseTemplate(htmlBody, emailModel);
    
    // Send the email with Configured Commerce's IEmailService
    var sendEmailParameter = new SendEmailParameter();
    sendEmailParameter.ToAddresses = new List<string>(){ "john.doe@test.com" };
    sendEmailParameter.FromAddress = "defaultemail@test.com";
    sendEmailParameter.Subject = "Welcome to our site";
    sendEmailParameter.Body = strEmailBody;
    try
    {
        emailService.Value.SendEmail(sendEmailParameter, unitOfWork);
    }
    catch (Exception e)
    {
        // Error handling
    }

    You can create a new template or edit an existing one. The IEmailService will send successfully as long as it is able to find the template name, and the placeholders match with the structure of your Email Model ExpandoObject:

    Mycustomemailtemplate

    Customize Email Templates

    DotLiquid is used to render the views of all email templates. However, seems like it’s not the standard DotLiquid syntax. The syntax has not been documented, this is what I found while inspecting the default templates:

    Placeholder Syntax

    The templating engine uses this syntax [[Model.PropertyName]] to render dynamic data from the Model. Since the Model is an ExpandoObject so you’re free to define any property inside. Also, there’re bunch of built-in variables for existing templates, please refer here: https://support.optimizely.com/hc/en-us/articles/4413199986957-HTML-variables-for-email-templates

    If-Else Statement

    Use this logic block when you want to render something conditionally.

    If:

    [% if Model.MyProperty != null and Model.MyProperty != "" -%]
        <p>[[Model.MyProperty]]</p>
    [% endif -%]

    If-Else:

    <strong>
        [% if Model.FirstName!= null and Model.FirstName!= "" -%] [[Model.FirstName]] [% else -%] [[Model.LastName]] [% endif -%]
    </strong>

    Iteration

    Use this block to loop through a list:

    [% for orderGroup in Model.OrderGroups -%]
        <div>
              <p>[[orderGroup.Heading]]</p>
        </div>
    [% endfor -%]

    Note: As of now (Jan 2025), the templating engine hasn’t supported nested loop yet.

    Site Messages

    You can even use Site Messages in your templates. For example:

    <span>[% siteMessage 'Welcome_Message' %]:</span>

    The cool thing about it is, Site Messages can be localizable. So based on SiteContext.Current.LanguageDto (from Insite.Core.Context), it can detect the current language and translate the message automatically for you.

    Welcomemessage

     

    I hope this information will be helpful when you need to work on Email Administration in Optimizely Configured Commerce. Happy coding!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleChristmas at Work: Bringing Joy to Your Office Celebrations
    Next Article Cybersecurity org ESET says get Linux if Windows 10 can’t be upgraded to Windows 11

    Related Posts

    Security

    Chrome Zero-Day Alert: CVE-2025-5419 Actively Exploited in the Wild

    June 2, 2025
    Security

    CISA Adds 5 Actively Exploited Vulnerabilities to KEV Catalog: ASUS Routers, Craft CMS, and ConnectWise Targeted

    June 2, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    Import TestNG results from Jenkins to ALM

    Development

    SambaNova and Hugging Face Simplify AI Chatbot Integration with One-Click Deployment

    Development

    CVE-2025-1421 – Konsola Proget Remote Code Execution Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Third-Party Data Breach Exposes Video Gaming Giant Roblox Developers’ Data

    Development

    Highlights

    CVE-2025-37828 – “ufs Linux Kernel NULL Pointer Dereference Vulnerability”

    May 8, 2025

    CVE ID : CVE-2025-37828

    Published : May 8, 2025, 7:15 a.m. | 58 minutes ago

    Description : In the Linux kernel, the following vulnerability has been resolved:

    scsi: ufs: mcq: Add NULL check in ufshcd_mcq_abort()

    A race can occur between the MCQ completion path and the abort handler:
    once a request completes, __blk_mq_free_request() sets rq->mq_hctx to
    NULL, meaning the subsequent ufshcd_mcq_req_to_hwq() call in
    ufshcd_mcq_abort() can return a NULL pointer. If this NULL pointer is
    dereferenced, the kernel will crash.

    Add a NULL check for the returned hwq pointer. If hwq is NULL, log an
    error and return FAILED, preventing a potential NULL-pointer
    dereference. As suggested by Bart, the ufshcd_cmd_inflight() check is
    removed.

    This is similar to the fix in commit 74736103fb41 (“scsi: ufs: core: Fix
    ufshcd_abort_one racing issue”).

    This is found by our static analysis tool KNighter.

    Severity: 0.0 | NA

    Visit the link for more details, such as CVSS details, affected products, timeline, and more…

    How to Fix Spotify ‘No PubKey’ Error on Ubuntu

    February 2, 2025

    Autonomous Robot Navigation and Efficient Data Collection: Human-Agent Joint Learning and Reinforcement-Based Autonomous Navigation

    July 7, 2024

    Create an agentic RAG application for advanced knowledge discovery with LlamaIndex, and Mistral in Amazon Bedrock

    May 29, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.