Email Body

Ivan Louw asked on May 21, 2019 07:01

Is there an API to read contains of CMS_Email table? I can read some of the email information by capturing events but I can't get email body for Async event. I also tried to implement CustomEmailProvider but message.body is empty. I am looking for a way to get whole email information. This info is store in CMS_Email table but I can't find API to read this in event handler or in custom task scheduler.

Recent Answers

Dmitry Bastron answered on May 21, 2019 11:38 (last edited on May 21, 2019 11:39)

Hi Ivan,

Have you tried CMS.EmailEngine.EmailInfoProvider provider which operates with CMS_Email table?

With it you can get CMS.EmailEngine.EmailInfo object containing EmailBody and other email related fields.

Please do not forget to mark the answer as correct if it is helpful

2 votesVote for this answer Mark as a Correct answer

Brenden Kehren answered on May 21, 2019 18:14

  • What version are you working in.
  • What does your event handler look like?
  • Where are you attempting to read this info?

Some event handlers don't have their respective context available due to when it is processed while others do. With the email queue, you will need to use the Global Object Events.

Your code might look like this:

using CMS;
using CMS.DataEngine;
using CMS.EmailEngine;
using CMS.Helpers;

// Registers the custom module into the system
[assembly: RegisterModule(typeof(CustomEmailEngineModule))]

public class CustomEmailEngineModule : Module
    // Module class constructor, the system registers the module under the name "CustomEmailEngine"
    public CustomEmailEngineModule()
        : base("CustomEmailEngine")

    // Contains initialization code that is executed when the application starts
    protected override void OnInit()

        // Assigns a handler to the Insert.After event for the ForumGroupInfo object type
        // This event occurs after the creation of every new email is added
        EmailInfo.TYPEINFO.Events.Insert.After += Emailinfo_Insert_After;

    private void Emailinfo_Insert_After(object sender, ObjectEventArgs e)
        // Checks that the email object group was successfully created
        if (e.Object != null)
            EmailInfo email = (EmailInfo)e.Object;

            // do your work here
            string htmlBody = email.EmailBody;
            string plainTextBody = email.EmailPlainTextBody;

The body should be completely rendered HTML with no macros in it. Those should have been resolved when the email was added to the queue.

1 votesVote for this answer Mark as a Correct answer

Ivan Louw answered on May 28, 2019 03:55

Thanks for the reply. The solution provided by Brenden worked. I am using Kentico 12 MVC.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.