AI agents: the content index is at /llms.txt. Every page is also available as Markdown — send the request header Accept: text/markdown, or append .md to the page URL.
Xperience Docs

Cookie consent

We use necessary cookies (opens in a new tab) to run our website and improve your experience while browsing. Additional cookies are only used with your consent. You may revoke your consent on the Cookies Policy (opens in a new tab) page or in your browser at any time.

Configure (opens in a new tab)
  • Documentation
    InstallationUsing the Xperience interfaceDeveloping websitesConfiguring XperienceManaging usersSecuring websitesDeploying websitesManaging website contentMultilingual websitesMacro expressionsExternal utilitiesIntegrating 3rd party systemsCustom developmentE-commerce featuresOn-line marketing featuresRelease notes - Xperience 13Xperience terminology glossary
  • Tutorial
    Using the Xperience interfaceDeveloper tutorialBusiness tutorialResource hub for marketers
  • API Examples
    ConfigurationContent managementDevelopmentE-commerceOn-line marketingSocial media
  1. Home
  2. On-line marketing
  3. Email marketing

Email marketing


Was this page helpful?

Send us feedback Go back to top
  • Community Questions & Answers (opens in a new tab)
  • Contact support (opens in a new tab)

List of examples:

  • Email marketing templates
    • Creating an email template
    • Updating an email template
    • Updating multiple email templates
    • Deleting an email template
  • Email feeds
    • Creating a newsletter
    • Creating an email campaign
    • Updating an email feed (any type)
    • Updating multiple email feeds (any type)
    • Deleting an email feed (any type)
  • Marketing emails
    • Creating marketing emails
    • Updating marketing emails
    • Deleting marketing emails
  • Recipients
    • Adding newsletter recipients by email address
    • Adding contacts as newsletter recipients
    • Adding newsletter recipients via contact groups
    • Unsubscribing an email address from a newsletter
    • Unsubscribing an email address from all newsletters
    • Removing a newsletter recipient
    • Adding email campaign recipients (contact groups)
    • Removing email campaign recipients (contact groups)

Email marketing templates

Creating an email template

C#
// Creates a new template object
EmailTemplateInfo newTemplate = new EmailTemplateInfo()
{
    // Sets the basic template properties
    TemplateDisplayName = "New email template",
    TemplateName = "NewEmailTemplate",
    TemplateSiteID = SiteContext.CurrentSiteID,

    // Sets the template type (template for marketing email content in this case)
    TemplateType = EmailTemplateTypeEnum.Issue,
    // Other possible template type values: EmailTemplateType.Subscription, EmailTemplateType.Unsubscription, EmailTemplateType.DoubleOptIn

    // Defines the content of the template
    TemplateCode = @"<html xmlns=""http://www.w3.org/1999/xhtml"">
                       <head>
                         <title>Newsletter</title>
                         <meta http-equiv=""content-type"" content=""text/html; charset=UTF-8"" />
                       </head>
                       <body>
                         Email template content
                       </body>
                     </html>"
};

// Saves the new template to the database
EmailTemplateInfo.Provider.Set(newTemplate);
> Back to list of examples

Updating an email template

C#
// Gets the email template
EmailTemplateInfo updateTemplate = EmailTemplateInfo.Provider.Get("NewEmailTemplate", SiteContext.CurrentSiteID);

if (updateTemplate != null)
{
    // Updates the template properties
    updateTemplate.TemplateDisplayName = updateTemplate.TemplateDisplayName.ToLower();

    // Saves the updated template to the database
    EmailTemplateInfo.Provider.Set(updateTemplate);
}
> Back to list of examples

Updating multiple email templates

C#
// Gets all email marketing templates of the "marketing email" type whose code name starts with 'New'
var templates = EmailTemplateInfo.Provider.Get()
                                            .WhereEquals("TemplateType", EmailTemplateTypeEnum.Issue)
                                            .WhereStartsWith("TemplateName", "New");

// Loops through individual email templates
foreach (EmailTemplateInfo template in templates)
{
    // Updates the template properties
    template.TemplateDisplayName = template.TemplateDisplayName.ToUpper();

    // Saves the updated template to the database
    EmailTemplateInfo.Provider.Set(template);
}
> Back to list of examples

Deleting an email template

C#
// Gets the email template
EmailTemplateInfo deleteTemplate = EmailTemplateInfo.Provider.Get("NewEmailTemplate", SiteContext.CurrentSiteID);

if (deleteTemplate != null)
{
    // Deletes the email template
    EmailTemplateInfo.Provider.Delete(deleteTemplate);
}
> Back to list of examples

Email feeds

Creating a newsletter

C#
// Gets templates for the newsletter's emails
EmailTemplateInfo subscriptionTemplate = EmailTemplateInfo.Provider.Get("SampleSubscriptionEmailTemplate", SiteContext.CurrentSiteID);
EmailTemplateInfo unsubscriptionTemplate = EmailTemplateInfo.Provider.Get("SampleUnsubscriptionEmailTemplate", SiteContext.CurrentSiteID);
EmailTemplateInfo emailTemplate = EmailTemplateInfo.Provider.Get("SampleEmailTemplate", SiteContext.CurrentSiteID);

if ((subscriptionTemplate != null) && (unsubscriptionTemplate != null) && (emailTemplate != null))
{
    // Creates a new email feed object
    NewsletterInfo newNewsletter = new NewsletterInfo()
    {
        // Sets the email feed properties to configure a newsletter
        NewsletterType = EmailCommunicationTypeEnum.Newsletter,
        NewsletterSource = NewsletterSource.TemplateBased,
        NewsletterDisplayName = "New newsletter",
        NewsletterName = "NewNewsletter",
        NewsletterSenderName = "Sender name",
        NewsletterSenderEmail = "sender@localhost.local",
        NewsletterSiteID = SiteContext.CurrentSiteID,

        // Assigns email templates to the newsletter
        NewsletterSubscriptionTemplateID = subscriptionTemplate.TemplateID,
        NewsletterUnsubscriptionTemplateID = unsubscriptionTemplate.TemplateID,
    };

    // Saves the new email feed to the database
    NewsletterInfo.Provider.Set(newNewsletter);

    EmailTemplateNewsletterInfo newEmailTemplateNewsletter = new EmailTemplateNewsletterInfo
    {
        NewsletterID = newNewsletter.NewsletterID,
        TemplateID = emailTemplate.TemplateID
    };

    EmailTemplateNewsletterInfo.Provider.Set(newEmailTemplateNewsletter);
}
> Back to list of examples

Creating an email campaign

C#
// Gets templates for the email campaign
EmailTemplateInfo subscriptionTemplate = EmailTemplateInfo.Provider.Get("SampleSubscriptionEmailTemplate", SiteContext.CurrentSiteID);
EmailTemplateInfo unsubscriptionTemplate = EmailTemplateInfo.Provider.Get("SampleUnsubscriptionEmailTemplate", SiteContext.CurrentSiteID);
EmailTemplateInfo emailTemplate = EmailTemplateInfo.Provider.Get("SampleEmailTemplate", SiteContext.CurrentSiteID);

if ((subscriptionTemplate != null) && (unsubscriptionTemplate != null) && (emailTemplate != null))
{
    // Creates a new email feed object
    NewsletterInfo newEmailCampaign = new NewsletterInfo()
    {
        // Sets the email feed properties to configure an email campaign
        NewsletterType = EmailCommunicationTypeEnum.EmailCampaign,
        NewsletterSource = NewsletterSource.TemplateBased,
        NewsletterDisplayName = "New email campaign",
        NewsletterName = "NewEmailCampaign",
        NewsletterSenderName = "Sender name",
        NewsletterSenderEmail = "sender@localhost.local",
        NewsletterSiteID = SiteContext.CurrentSiteID,

        // Assigns templates to the email campaign
        NewsletterSubscriptionTemplateID = subscriptionTemplate.TemplateID,
        NewsletterUnsubscriptionTemplateID = unsubscriptionTemplate.TemplateID,
    };

    // Saves the new email feed to the database
    NewsletterInfo.Provider.Set(newEmailCampaign);

    EmailTemplateNewsletterInfo newEmailTemplateCampaign = new EmailTemplateNewsletterInfo
    {
        NewsletterID = newEmailCampaign.NewsletterID,
        TemplateID = emailTemplate.TemplateID
    };

    EmailTemplateNewsletterInfo.Provider.Set(newEmailTemplateCampaign);
}
> Back to list of examples

Updating an email feed (any type)

C#
// Gets the email feed
NewsletterInfo updateEmailFeed = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if (updateEmailFeed != null)
{
    // Updates the email feed properties
    updateEmailFeed.NewsletterDisplayName = updateEmailFeed.NewsletterDisplayName.ToLower();

    // Saves the updated email feed to the database
    NewsletterInfo.Provider.Set(updateEmailFeed);
}
> Back to list of examples

Updating multiple email feeds (any type)

C#
// Gets all email feeds on the current site whose code name starts with 'New'
var emailFeeds = NewsletterInfo.Provider.Get()
                                                .WhereEquals("NewsletterSiteID", SiteContext.CurrentSiteID)
                                                .WhereStartsWith("NewsletterName", "New");

// Loops through individual email feeds
foreach (NewsletterInfo emailFeed in emailFeeds)
{
    // Updates the email feed properties
    emailFeed.NewsletterDisplayName = emailFeed.NewsletterDisplayName.ToUpper();

    // Saves the updated email feed to the database
    NewsletterInfo.Provider.Set(emailFeed);
}
> Back to list of examples

Deleting an email feed (any type)

C#
// Gets the email feed
NewsletterInfo deleteEmailFeed = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if (deleteEmailFeed != null)
{
    // Deletes the email feed
    NewsletterInfo.Provider.Delete(deleteEmailFeed);
}
> Back to list of examples

Marketing emails

Creating marketing emails

C#
// Gets the email feed (Newsletter or Email campaign)
NewsletterInfo emailFeed = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

EmailTemplateNewsletterInfo assignedTemplate = EmailTemplateNewsletterInfo.Provider.Get()
    .WhereEquals("NewsletterID", emailFeed.NewsletterID)
    .TopN(1)
    .FirstOrDefault();

if (emailFeed != null)
{
    // Creates a new email object
    IssueInfo newIssue = new IssueInfo()
    {
        // Sets the email properties
        IssueDisplayName = "New issue name",
        IssueSubject = "New issue subject",
        IssueNewsletterID = emailFeed.NewsletterID,
        IssueSiteID = SiteContext.CurrentSiteID,
        IssueStatus = IssueStatusEnum.Idle,
        IssueUnsubscribed = 0,
        IssueSentEmails = 0,
        IssueTemplateID = assignedTemplate.TemplateID,
        IssueUseUTM = false,
        IssueText = string.Empty,

        // Defines the email content
        // This XML is being generated by the Email builder
        IssueWidgets = "<?xml version=\"1.0\" encoding=\"utf-16\"?>"
    };

    // Saves the marketing email to the database
    IssueInfo.Provider.Set(newIssue);
}
> Back to list of examples

Updating marketing emails

C#
// Gets the email feed
NewsletterInfo emailFeed = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if (emailFeed != null)
{
    // Gets all of the feed's emails that have not been sent yet
    var issues = IssueInfo.Provider.Get()
                                        .WhereEquals("IssueNewsletterID", emailFeed.NewsletterID)
                                        .WhereNull("IssueStatus");

    // Loops through individual emails
    foreach (IssueInfo issue in issues)
    {
        // Updates the email properties
        issue.IssueSubject = issue.IssueSubject.ToUpper();

        // Saves the modified email to the database
        IssueInfo.Provider.Set(issue);
    }
}
> Back to list of examples

Deleting marketing emails

C#
// Gets the email feed
NewsletterInfo emailFeed = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if (emailFeed != null)
{
    // Gets all of the feed's emails that were already sent
    var issues = IssueInfo.Provider.Get()
                                        .WhereEquals("IssueNewsletterID", emailFeed.NewsletterID)
                                        .WhereEquals("IssueStatus", IssueStatusEnum.Finished);

    // Loops through individual emails
    foreach (IssueInfo deleteIssue in issues)
    {
        // Deletes the email
        IssueInfo.Provider.Delete(deleteIssue);
    }
}
> Back to list of examples

Recipients

Adding newsletter recipients by email address

C#
// Prepares the email address of the new recipient
string emailAddress = "subscriber@localhost.local";

// Gets the newsletter
NewsletterInfo newsletter = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if (newsletter != null)
{
    // Prepares instances of the Xperience contact provider and email feed subscription service
    IContactProvider contactProvider = CMS.Core.Service.Resolve<IContactProvider>();
    ISubscriptionService subscriptionService = CMS.Core.Service.Resolve<ISubscriptionService>();

    // Either gets an existing contact by email address or creates a new contact with the given email address
    ContactInfo contact = contactProvider.GetContactForSubscribing(emailAddress);

    // Adds the contact as a recipient of the newsletter
    subscriptionService.Subscribe(contact, newsletter, new SubscribeSettings
    {
        AllowOptIn = true, // Allows double opt-in subscription for newsletters that have it enabled
        SendConfirmationEmail = true, // Allows sending of confirmation emails for the subscription

        // Removes the email address from the opt-out list for all marketing emails on the given site (if present)
        RemoveAlsoUnsubscriptionFromAllNewsletters = true,
    });
}
> Back to list of examples

Adding contacts as newsletter recipients

C#
// Gets all contacts whose last name is 'Smith'
var contacts = ContactInfo.Provider.Get()
                                    .WhereEquals("ContactLastName", "Smith");

// Gets the newsletter
NewsletterInfo newsletter = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if (newsletter != null)
{
    // Prepares an instance of the Xperience email feed subscription service
    ISubscriptionService subscriptionService = CMS.Core.Service.Resolve<ISubscriptionService>();

    // Loops through the contacts
    foreach (ContactInfo contact in contacts)
    {
        // Adds the contact as a recipient of the newsletter
        subscriptionService.Subscribe(contact, newsletter, new SubscribeSettings
        {
            AllowOptIn = true, // Allows double opt-in subscription for newsletters that have it enabled
            SendConfirmationEmail = true, // Allows sending of confirmation emails for the subscription

            // Removes the contact from the opt-out list for all marketing emails on the given site (if present)
            RemoveAlsoUnsubscriptionFromAllNewsletters = true,
        });
    }
}
> Back to list of examples

Adding newsletter recipients via contact groups

C#
// Gets the contact group
ContactGroupInfo contactGroup = ContactGroupInfo.Provider.Get("GroupName");

// Gets the newsletter
NewsletterInfo newsletter = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if ((contactGroup != null) && (newsletter != null))
{
    // Prepares an instance of the Xperience email feed subscription service
    ISubscriptionService subscriptionService = CMS.Core.Service.Resolve<ISubscriptionService>();

    // Adds the contact group as a recipient of the newsletter
    subscriptionService.Subscribe(contactGroup, newsletter);
}
> Back to list of examples

Unsubscribing an email address from a newsletter

C#
// Prepares the email address that you wish to unsubscribe
string emailAddress = "subscriber@localhost.local";

// Gets the newsletter
NewsletterInfo newsletter = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if (newsletter != null)
{
    // Prepares an instance of the Xperience email feed subscription service
    ISubscriptionService subscriptionService = CMS.Core.Service.Resolve<ISubscriptionService>();

    // Ensures that the email address no longer receives the newsletter's emails
    // Leaves the email address in the newsletter's list of recipients, but with the "Opted out" status
    subscriptionService.UnsubscribeFromSingleNewsletter(emailAddress, newsletter.NewsletterID, null, sendConfirmationEmail: true);
}
> Back to list of examples

Unsubscribing an email address from all newsletters

C#
// Prepares the email address that you wish to unsubscribe
string emailAddress = "subscriber@localhost.local";

if (!string.IsNullOrEmpty(emailAddress))
{
    // Prepares an instance of the Xperience email feed subscription service
    ISubscriptionService subscriptionService = CMS.Core.Service.Resolve<ISubscriptionService>();

    // Ensures that the email address no longer receives email newsletters
    subscriptionService.UnsubscribeFromAllNewsletters(emailAddress);
}
> Back to list of examples

Removing a newsletter recipient

C#
// Gets the subscriber that you wish to remove from the list of recipients (by email address)
SubscriberInfo subscriber = SubscriberInfoProvider.GetSubscriberByEmail("subscriber@localhost.local", SiteContext.CurrentSiteID);

// Gets the newsletter
NewsletterInfo newsletter = NewsletterInfo.Provider.Get("NewNewsletter", SiteContext.CurrentSiteID);

if ((subscriber != null) && (newsletter != null))
{
    // Prepares an instance of the Xperience email feed subscription service
    ISubscriptionService subscriptionService = CMS.Core.Service.Resolve<ISubscriptionService>();

    // Removes the subscriber from the newsletter's recipients
    subscriptionService.RemoveSubscription(subscriber.SubscriberID, newsletter.NewsletterID, sendConfirmationEmail: true);
}
> Back to list of examples

Adding email campaign recipients (contact groups)

C#
// Gets the contact group
ContactGroupInfo contactGroup = ContactGroupInfo.Provider.Get("GroupName");

// Gets the email campaign
NewsletterInfo emailCampaign = NewsletterInfo.Provider.Get("NewEmailCampaign", SiteContext.CurrentSiteID);

if ((contactGroup != null) && (emailCampaign != null))
{
    // Gets the campaign's email with the subject "New issue"
    IssueInfo campaignEmail = IssueInfo.Provider.Get()
                                        .WhereEquals("IssueNewsletterID", emailCampaign.NewsletterID)
                                        .WhereEquals("IssueSubject", "New issue")
                                        .TopN(1)
                                        .FirstOrDefault();

    if (campaignEmail != null)
    {
        // Creates an object representing a relationship between the campaign email and contact group
        var emailContactGroupBinding = new IssueContactGroupInfo
        {
            ContactGroupID = contactGroup.ContactGroupID,
            IssueID = campaignEmail.IssueID
        };

        // Assigns the contact group as a recipient for the campaign email
        IssueContactGroupInfo.Provider.Set(emailContactGroupBinding);
    }
}
> Back to list of examples

Removing email campaign recipients (contact groups)

C#
// Gets the contact group
ContactGroupInfo contactGroup = ContactGroupInfo.Provider.Get("GroupName");

// Gets the email campaign
NewsletterInfo emailCampaign = NewsletterInfo.Provider.Get("NewEmailCampaign", SiteContext.CurrentSiteID);

if ((contactGroup != null) && (emailCampaign != null))
{
    // Gets the campaign's email with the subject "New issue"
    IssueInfo campaignEmail = IssueInfo.Provider.Get()
                                        .WhereEquals("IssueNewsletterID", emailCampaign.NewsletterID)
                                        .WhereEquals("IssueSubject", "New issue")
                                        .TopN(1)
                                        .FirstOrDefault();

    if (campaignEmail != null)
    {
        // Gets the object representing the relationship between the campaign email and contact group
        IssueContactGroupInfo emailContactGroupBinding =
            IssueContactGroupInfo.Provider.Get(campaignEmail.IssueID, contactGroup.ContactGroupID);

        if (emailContactGroupBinding != null)
        {
            // Removes the contact group from the campaign email's recipient list
            IssueContactGroupInfo.Provider.Delete(emailContactGroupBinding);
        }
    }
}
> Back to list of examples