Magento Transactional Email Codes - Custom Emails
Feb 10, 2011 · 2 minute readCategory: magento
If you need to send some custom emails as part of a custom Magento module development project, you will stumble into the Magento email template system and its confusing mixture of XML requirements.
Rather than go into too much detail here are some pointers about how to achieve what you want to do.
- You need to set up your admin options in your system.xml file.
I’m not going to go into the details on how to set up custom admin configuration, for that try here.
Lets assume you have a custom module under the xml path:
config/sections/custom_module/groups/email/template
that section should look something like this:
<template translate="label">
<label>Custom Email Template</label>
<frontend_type>select</frontend_type>
<source_model>adminhtml/system_config_source_email_template</source_model>
<sort_order>2</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</template>
You need to set your default value in your config.xml file (inside the root config tag)
<!-- DEFAULTS For Admin System Configuration //-->
<default>
<custom_module>
<email>
<enabled>1</enabled>
<template>custom_module_email_template</template>
<identity>sales</identity>
</email>
</custom_module>
</default>
Now you also need to define your email template, which goes inside the config/global/ node
<!-- EMAIL TEMPLATE //-->
<template>
<email>
<custom_module_email_template translate="label" module="appliedsb">
<label>Custom Template</label>
<file>appliedsb/download_links.html</file>
<type>html</type>
</custom_moduel_email_template>
</email>
</template>
And then you need to make sure you put the email template inside the locale folder, en_us (or other locales as needed).
Now you need to clear cache and I recommend resaving the custom configuration group in the admin and double check that your Custom Template label is appearing properly in the email templates dropdown for your module.
And that should be it, your module now has a custom email template that has a locale file and is also over rideable with Magento’s own transactional emails system - sweet!
If you get the exception Invalid transactional email code: then double check that all your xml nodes match up and that the locale file is in the correct place, clear your cache, resave the admin config and try again. This bug can be tricky to track down but if you respect the above xml and file layout it should all work.