Creating Custom Email / Message Templates

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
Il y a 13 ans
I want to create my own email templates to support my custom features. Can I do this? If not, can someone suggest a workaround.

Thanks!
Il y a 13 ans
bump.  I'm wondering the same thing!  This would be incredibly helpful.
Il y a 13 ans
If you've got the source code, then it's easy to add another function that mimics e.g. MessageManager.SendCustomerPasswordRecoveryMessage, but uses a different template name. And then use the Administration UI to author the email template for that name.

In fact, MessageManager looks ripe for a Refactoring. A lot of the routines follow exactly the same structure and perhaps a function as per below would be worth including in the next build?


        /// <summary>
        /// Sends generic message to a customer, using a specific template
        /// </summary>
        /// <param name="customer">Customer instance</param>
        /// <param name="languageId">Message language identifier</param>
        /// <param name="templateName">Name of template to use</param>
        /// <returns>Queued email identifier</returns>
        public static int SendMessageFromTemplate(Customer customer, int languageId, string templateName)
        {
            if (customer == null)
                throw new ArgumentNullException("customer");
            if(string.IsNullOrEmpty(templateName))
                throw new ArgumentNullException("templateName");

            var localizedMessageTemplate = MessageManager.GetLocalizedMessageTemplate(templateName, languageId);
            if (localizedMessageTemplate == null || !localizedMessageTemplate.IsActive)
                return 0;

            var emailAccount = localizedMessageTemplate.EmailAccount;

            string subject = ReplaceMessageTemplateTokens(customer, localizedMessageTemplate.Subject);
            string body = ReplaceMessageTemplateTokens(customer, localizedMessageTemplate.Body);
            string bcc = localizedMessageTemplate.BccEmailAddresses;
            var from = new MailAddress(emailAccount.Email, emailAccount.DisplayName);
            var to = new MailAddress(customer.Email, customer.FullName);
            var queuedEmail = InsertQueuedEmail(5, from, to, string.Empty, bcc, subject, body,
                DateTime.UtcNow, 0, null, emailAccount.EmailAccountId);
            return queuedEmail.QueuedEmailId;
        }
Il y a 13 ans
Try http://www.stringtemplate.org/

I have been using String Template and it has many features. You can pass collections into and it formats templates accordingly.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.