One of the things that MageMail does is that it pulls relevant product images into various email templates. For example, the abandoned cart email contains images of the items that were abandoned.
If you use Magento’s out of the box image fetching code, you’ll get a nice resized and cached version of the product shot. So far so good, right? Well the problem with including such a URL in an email is that when the media cache is cleared, all of a sudden you have a lot of emails in the wild with broken image URLs.
So the most obvious solution is to bypass Magento’s image caching and just grab direct URLs to the source image. But then you’re losing the image resizing functionality, which is important to be able to format a nice square version of a product shot that will sit nicely within a product image grid.

Depending upon the way the product shots are composed, that may work out for you. But then there’s still the problem of the product itself being modified on the product. This is a lot less of a concern than cache clearing as it will be a lot less frequent, but still something to keep in mind.
The Solution
Okay so the solution that I came up with is really pretty basic – you setup a controller on the Magento side that can accept a product ID, an image type (image, small_image, etc.), and width and height dimensions.
That controller is responsible for checking for the existence of a cached version of that image and returning it. If a cached version exists, it returns it straight away, but if the cache has since been cleared, it will re-generate the image fresh.
So the URL to that controller will always be valid, and is therefore safe to be sitting around in emails in the wild.
The only downside to this approach is that your images aren’t being served directly from a CDN – but there’s not much that you can do about that in the context of email. In the context of a website, you can always simply refresh the image paths dynamically.




