Sending emails with assets and generated links using CLI in Pimcore

What you'll learn with this guide 

In this guide, you will learn the configuration steps needed to properly include assets and generated links in emails sent through a command in Pimcore.

Where to use

One of many use cases is sending automatic emails to your users or clients. Every email nowadays contains a logo or some other sort of asset and/or links! Without first setting things up in your Pimcore admin panel and project files you will not be able to send emails with the above-mentioned properties if they are sent through the command line.

Solution

Let’s start with the admin panel in Pimcore. For Pimcore to know the base_url for your assets when sending emails we need to configure System Settings > Website.

Configuring System settings in Pimcore administration

 

Now change the Main Domain property to your website URL (if you are running Pimcore locally change it to your local IP address), and save your changes.

Configuring the main domain setting in Pimcore administration

 

An example of what would happen if we are sending emails through the command line without setting the Main Domain property is that the assets would not generate a valid full path. 

E.g. you’re sending images of products within your email and they are located in a folder called Products within your assets. The generated full path without changing this setting would look like this: “/Products/image_example.jpg” and therefore will not show up in your email, but with the configuration set, it will be “http://example.com/Products/image_example.jpg”.

The next step is configuring your router. To generate links we need to use the RouterInterface which uses the current request to generate the base_url for your link. To set the router parameters (since we don’t have a request to configure it) we will need to edit the parameters.yml file located in my-project/app/config/parameters.yml.

Add a new parameter called router.request_context.base_url and pass your base_url.
 

E.g.

parameters:
          router.request_context.base_url: example.com


After adding all of the above-mentioned changes please clear your cache (bin/console c:c) to make sure the changes are loading correctly. 

That’s it!

Does it work?

To test if your emails are configured correctly, send an email using your command line and check if the URL-s generated for all of your assets and links contain a base_url.

If you'd like some help with Pimcore, feel free to say hello@factory.dev! 

Looking for Exponential Growth? Let’s Get Started.
Explore next

Pimcore Tutorial

Check out our step-by-step tutorials on how to use Pimcore features and solutions.

Discover more