Set ReplyTo for newsletter issue

Roman Čapek asked on August 8, 2025 09:12

I am trying to implement and handle the "Reply-to" field for marketing emails sent as part of a newsletter issue. I successfully added the field to the Kentico class and included it in the Email Builder. As a result, each created newsletter issue now stores the desired value in the database under the Newsletter_Issue entry.

However, I cannot find a way to use this value in the "Reply-to" field for outgoing emails. I followed the instructions provided here, but there is no event available that contains the final email messages, and as a result, I am unable to set the "Reply-to" field.

Is there any other method or workaround to achieve this in Kentico? We are using Kentico v12.0.103 (Portal Engine).

Recent Answers


vasu yerramsetti answered on August 10, 2025 16:39 (last edited on August 10, 2025 16:40)

Use EmailSender.SendEmail global handler: You can hook into the low-level send process by registering a handler for EmailSender.SendEmail.Before in a global module.

using CMS;
using CMS.EmailEngine;
using CMS.Newsletters;

[assembly: RegisterModule(typeof(CustomEmailReplyToModule))]

public class CustomEmailReplyToModule : Module
{
    public CustomEmailReplyToModule() : base("CustomEmailReplyToModule") { }

    protected override void OnInit()
    {
        base.OnInit();

        // Hook BEFORE send
        EmailSender.SendEmail.Before += SendEmail_Before;
    }

    private void SendEmail_Before(object sender, EmailSenderEventArgs e)
    {
        var issueGuid = e.EmailMessage.EmailID; // Not directly the issue ID
        // The tricky part: identify if this is a newsletter email
        // and fetch the ReplyTo value from your custom field

        var issue = NewsletterIssueInfo.Provider.Get()
            .WhereEquals("IssueGUID", e.EmailMessage.EmailGuid)
            .FirstOrDefault();

        if (issue != null && !string.IsNullOrEmpty(issue.GetString("ReplyTo", "")))
        {
            e.EmailMessage.ReplyTo = issue.GetString("ReplyTo", "");
        }
    }
}

If you want to set the ReplyTo before messages get queued, hook into newsletter issue generation:

using CMS;
using CMS.Newsletters;

[assembly: RegisterModule(typeof(CustomNewsletterReplyToModule))]

public class CustomNewsletterReplyToModule : Module
{
    public CustomNewsletterReplyToModule() : base("CustomNewsletterReplyToModule") { }

    protected override void OnInit()
    {
        base.OnInit();

        NewsletterSender.SendIssue_Before += NewsletterSender_SendIssue_Before;
    }

    private void NewsletterSender_SendIssue_Before(object sender, NewsletterSenderEventArgs e)
    {
        var issue = e.Issue;
        if (issue != null && !string.IsNullOrEmpty(issue.GetString("ReplyTo", "")))
        {
            // This won't set Reply-To directly here,
            // but you can store it in e.Issue or a custom property
            // to later pick up in EmailSender.SendEmail.Before
        }
    }
}
0 votesVote for this answer Mark as a Correct answer

Roman Čapek answered on August 15, 2025 10:29

Dear Vasu,

thank you for your quick response! I was trying to implement custom modules earlier, however, I cannot reproduce the way you suggested. EmailSender.SendEmail is a method, not an event that I can use for registering my own handler. I was also trying to use Newsletter specific events like NewsletterEvents.GenerateQueueItems.Before but such an event does not inlcude a way how to modify the generated emails. So, even though I understand the suggested approach and willing to use, I still can't find the correct event to register. Am I missing something?

0 votesVote for this answer Mark as a Correct answer

Roman Čapek answered on August 15, 2025 10:34

The EmailSender class I have available in Kentico code (decompiled) is the following:

using CMS.Base;
using CMS.DataEngine;
using CMS.MacroEngine;

namespace CMS.EmailEngine
{
    public static class EmailSender
    {
        public static void SendEmail(EmailMessage message);

        public static void SendEmail(string siteName, EmailMessage message, string templateName, MacroResolver resolver, bool sendImmediately);

        public static void SendEmail(string siteName, EmailMessage message, bool sendImmediately = false);

        public static void SendEmailWithTemplateText(string siteName, EmailMessage message, EmailTemplateInfo template, MacroResolver resolver, bool sendImmediately);

        public static void SendMassEmails(EmailMessage message, string userIds, string roleIds, string groupIds, int siteId, bool sendToEveryone = false);

        public static void SendTestEmail(string siteName, EmailMessage message, SMTPServerInfo smtpServer);
    }
}
0 votesVote for this answer Mark as a Correct answer

vasu yerramsetti answered on August 18, 2025 07:29 (last edited on August 18, 2025 11:23)

Try with this EmailEvents.Send.Before

Kentico provides EmailEvents which wrap the send pipeline. This is the lowest-level, correct way to intercept outgoing messages:

using CMS;
using CMS.EmailEngine;

[assembly: RegisterModule(typeof(CustomEmailReplyToModule))]

public class CustomEmailReplyToModule : Module
{
    public CustomEmailReplyToModule() : base("CustomEmailReplyToModule") { }

    protected override void OnInit()
    {
        base.OnInit();

        // hook into email events
        EmailEvents.Send.Before += Send_Before;
    }

    private void Send_Before(object sender, EmailEventArgs e)
    {
        var email = e.Email;

        // You can now inspect and modify the outgoing message
        if (email.EmailFormat == EmailFormatEnum.Html && string.IsNullOrEmpty(email.ReplyTo))
        {
            // Example: add Reply-To dynamically
            email.ReplyTo = "replyto@yourdomain.com";
        }
    }
}
0 votesVote for this answer Mark as a Correct answer

Roman Čapek answered on August 18, 2025 15:00

Dear Vasu,

I am almost worried to write another bad news regarding your advice. There is no EmailEvents in our Kentico. I have prepared an overview of all the events we cas access (based on reflection and naming convention), it can be accessed on our website: https://www.nadacepartnerstvi.cz/specialni/avaliable-events. Bold is the class containing event members, italic are the fields and the field type is in brackets. From my point of view, I can't find anything that would allow me to access the Send event.

Sory for repeating question, but I still can't find a proper way to handle what we need.

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on August 19, 2025 07:15

The NewsletterEvents has the GenerateQueueItems event in which you should be able to get the generated emails and adjust them. If not, if you are sending the isues through email queue, I would try using the EmailInfo object events - then you would need to edit each email, so you need to be careful about the performance.

0 votesVote for this answer Mark as a Correct answer

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