Skip to content

Conversation

shinde-rahul
Copy link
Contributor

@shinde-rahul shinde-rahul commented Apr 28, 2025

  • Updated Email Preview, Email Send Example, and Send from Contact actions
  • Enriched both real and fake contacts with their primary company information
  • Improved token replacements by ensuring company tokens are available
  • Added prepareFakeContactWithPrimaryCompany() for generating realistic fake contacts
Q A
Bug fix? (use the a.b branch)
New feature/enhancement? (use the a.x branch) ✔️
Deprecations?
BC breaks? (use the c.x branch)
Automated tests included? ✔️
Related user documentation PR URL mautic/user-documentation#...
Related developer documentation PR URL mautic/developer-documentation-new#...
Issue(s) addressed Fixes #...

Description

This PR improves how we enrich contact data with company info for email previews, example sends, and regular sends from a contact list or detail page.
It ensures {contactfield=companyname} and similar company tokens work reliably, even when there’s no real contact selected.

✨ Change log

  • Updated sendExampleAction and previewAction to use enriched contacts.
  • Added prepareFakeContactWithPrimaryCompany() to create realistic fake contact+company data for previews.
  • Ensured that token replacements include company information for both real and imaginary contacts.

User stories

  1. Email Preview
    As a marketing user,
    I want the contact used in email previews to include the primary company information,
    so that I can verify if all tokens, including company tokens, are correctly replaced before sending the email.

  2. Example email
    As a marketing user,
    I want the example emails I send to myself (or others) to use an enriched contact that includes primary company details,
    so that I can test if personalization tokens for contacts and their companies are working correctly.

  3. Send Email from Contact Listing
    As a marketing user,
    I want to ensure that when sending an email from a contact's listing or detail view, the email uses a contact record enriched with its primary company information,
    so that all contact and company tokens populate correctly in the sent email.


📋 Steps to test this PR:

  1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs here)

  2. Create a Company and a Contact
    → Associate the contact with the company you just created.

  3. Create an Email
    → Add company-related tokens like {contactfield=companyname} in the email body.

  4. Check the Preview
    → Open the email in preview mode
    → Try previewing with and without selecting a contact
    → You should see company tokens rendered either way (real or fake data).

  5. Send an Example Email
    → On the Email detail page, use the Edit dropdown → Send Example
    → Check that company tokens are correctly rendered in the received email.

  6. Send Email from Contact Listing
    → Go to the Contact listing page
    → Use the options menu for a contact → Send Email
    → Choose the email and send
    → Confirm company tokens are filled in as expected.

Updated Email Preview, Email Send Example, and Send from Contact actions

Enriched both real and fake contacts with their primary company information

Improved token replacements by ensuring company tokens are available

Added prepareFakeContactWithPrimaryCompany() for generating realistic fake contacts
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.25%. Comparing base (70f0773) to head (a9666b4).
⚠️ Report is 1317 commits behind head on 7.x.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                7.x   #14944   +/-   ##
=========================================
  Coverage     66.25%   66.25%           
- Complexity    35147    35150    +3     
=========================================
  Files          2314     2315    +1     
  Lines        141589   141594    +5     
=========================================
+ Hits          93809    93814    +5     
  Misses        47780    47780           
Files with missing lines Coverage Δ
...bundles/EmailBundle/Controller/EmailController.php 67.22% <100.00%> (-0.18%) ⬇️
...undles/EmailBundle/Controller/PublicController.php 59.67% <100.00%> (-0.74%) ⬇️
app/bundles/EmailBundle/Model/EmailModel.php 54.68% <100.00%> (ø)
...p/bundles/LeadBundle/Controller/LeadController.php 61.75% <100.00%> (+0.02%) ⬆️
...pp/bundles/LeadBundle/Helper/FakeContactHelper.php 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@shinde-rahul shinde-rahul marked this pull request as ready for review April 29, 2025 11:44
@shinde-rahul shinde-rahul requested review from escopecz, kuzmany, abhisekmazumdar and adiux and removed request for escopecz April 29, 2025 11:45
@shinde-rahul shinde-rahul added ready-to-test PR's that are ready to test code-review-needed PR's that require a code review before merging email Anything related to email labels Apr 29, 2025
@shinde-rahul shinde-rahul moved this to 🧑🏻‍💻 Needs a code review in Open Source Fridays Apr 29, 2025
@shinde-rahul shinde-rahul added the refactoring The change does not change behavior but improves the code label Apr 30, 2025
Copy link

@Bastian2718 Bastian2718 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! For Customfields too!

@imaabasiee
Copy link

@shinde-rahul please how do I add company-related tokens like {contactfield=companyname} in the email body in step 3? Thank you.

@shinde-rahul
Copy link
Contributor Author

@imaabasiee, Here is the page containing all tokens that can be used https://docs.mautic.org/en/5.x/configuration/variables.html

Copy link
Member

@kuzmany kuzmany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I fix #12620 I notice issue with company tokens in send custom email. This PR fixed
Code seems legit too 👍

@kuzmany kuzmany added pending-test-confirmation PR's that require one test before they can be merged code-review-passed PRs which have passed code review and removed code-review-needed PR's that require a code review before merging ready-to-test PR's that are ready to test labels May 30, 2025
@escopecz escopecz added this to the 7.0.0-alpha milestone May 30, 2025
@escopecz escopecz added user-testing-passed PRs which have been successfully tested by the required number of people. and removed pending-test-confirmation PR's that require one test before they can be merged labels May 30, 2025
@escopecz escopecz merged commit 90ab536 into mautic:7.x May 30, 2025
20 checks passed
@github-project-automation github-project-automation bot moved this from 🧑🏻‍💻 Needs a code review to 🥳 Done in Open Source Fridays May 30, 2025
@escopecz escopecz added the enhancement Any improvement to an existing feature or functionality label Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code-review-passed PRs which have passed code review email Anything related to email enhancement Any improvement to an existing feature or functionality refactoring The change does not change behavior but improves the code user-testing-passed PRs which have been successfully tested by the required number of people.
Projects
Status: 🥳 Done
Development

Successfully merging this pull request may close these issues.

5 participants