When sending an automated email filled by an external source like an RSS feed, JSON feed, or API, you might not always have complete control over the content that ends up being displayed in the email. For example, when working with recommendations, the external source might provide only one product while your content expects three. Even worse, the source could be empty.
With the cancel_mail function, you can cancel the entire email delivery or just the delivery for the current customer. So, if the external source doesn't provide any or only one product, you can stop the email delivery for the current customer.
In situations where the content is not as expected or when there's not enough content to fill the email, the cancel_mail function allows you to prevent sending incomplete or incorrect emails to customers.
Arguments
The following arguments can be used with the cancel_mail:
Argument | Description |
---|---|
for | The ability to indicate whether the delivery should be canceled for the entire selection or only the current customer for whom the email is being rendered. By default, this is for the current customer. The following values are available:
|
Examples
Example with an product feed
Below is an example in combination with a product feed that is retrieved using the DataFeeds app, using the XML provided below:
<rss xmlns:g="http://base.google.com/ns/1.0" version="2.0">
<channel>
<item>
<id>1</id>
<title>Home loungeset Cardona</title>
<category>Tuinset</category>
<url>https://example.org/first-item</url>
<image>https://example.org/first-item.png</image>
<price>599.00</price>
<availability>In Stock</availability>
</item>
<item>
<id>2</id>
<title>Home loungeset Örebro</title>
<category>Tuinset</category>
<url>https://example.org/second-item</url>
<image>https://example.org/second-item.png</image>
<price>279.00</price>
<availability>In Stock</availability>
</item>
<item>
<id>3</id>
<title>Home loungeset Claire</title>
<category>Tuinset</category>
<url>https://example.org/third-item</url>
<image>https://example.org/third-item.png</image>
<price>479.00</price>
<availability>Sold out</availability>
</item>
</channel>
</rss>
In this process, it is checked whether there are products present in the feed and whether there is a sellable product among them. If these conditions are not met, the delivery is canceled for the entire selection. In this example, along with the cancel_mail function, the following Smarty methods are used: getRss, foreach, if, empty, lower, and counter: