Confinity Documentation
  • Latest Version
  • Latest Version
  • Getting Started

    • Introduction
    • Core Concepts
    • Create an Application
    • Glossary
  • Essentials

    • Authentication & SSO
    • Breaking Changes
    • Roslyn Source Analyzers
    • Changelog
    • ConfinityContent
    • ConfinitySelectable
    • Confinity Schedules
    • Data Seeding
    • Development guidelines [WIP]
    • Entity App
    • Entity Form
    • Entity Permissions
    • Frontend Configuration
    • Images
    • Known Issues
    • Localization
    • Migrations
    • Modules [WIP]
    • On-Site Editing
    • Settings
    • Cascade Delete
    • Replication
    • Infrastructure
  • Modules

    • Analytics Module
    • Assets Module
    • Blog Module
    • Cookie Consent Module
    • Forms Module
    • Friendly Captcha (Forms Module )
    • GeoIP Module
    • Htmx
    • Mail Module
    • Mailing Module
    • MediaPlayer Module
    • GoogleMyBusiness Module
    • OpenTelemetry Module
    • Pages Module [WIP]
    • Pattern Library Module
    • SIX Saferpay (worldline) Module
    • Products Module
    • Search Module
    • Wizard Module
  • Guides

    • Create a Custom Entity App Form Element
    • Date and Time
    • Entity Change Listener
    • File Upload / Temp File
    • HTTP security headers
    • conventions [WIP]
    • How to use Confinity with nginx
    • Notifications
    • Nullability
    • Rename Entity
    • Schedules
    • Useful snippets
    • Content Localization
  • Design Guidelines

    • Introduction
    • Page Components
    • Forms Module

Mailing Module

The mailing module brings the functionality to send mass e-mails (newsletters). Tough Confinity is not sending the e-mails itself, it offers interfaces to mailing providers (e.g. https://www.xcampaign.info/switzerland-en/).

URL generation

Confinity creates a HttpContext and needs a configured web site to do so.It will use the first web site in the pages tree with a primary domain.

Implement a Mailing Layout

For authors to be able to create a mailing, developers must provide some implementations first.

  1. Define a model that contains all properties needed to create the mailing.

public sealed class GoodNewsLayoutModel : LayoutModel
{
    public string? MailshotForeignId { get; set; }
    public string? Subject { get; set; }
    public string? Text { get; set; }
    public LinkModel? Url { get; set; }
}

  1. Implement a IMailingModelConverter for your model that creates a provider specific model. In the example, XCampaingn was chosen with the XCampaignSendMailModel.

public class MailingLayoutConverter : IMailingModelConverter
{
    private readonly ILinkHelper _linkHelper;

    public MailingLayoutConverter(ILinkHelper linkHelper)
    {
        _linkHelper = linkHelper;
    }

    public async Task<ConvertSendMailResult> ConvertAsync(SendMailModel sendMailModel)
    {
        var goodNewsLayout = (GoodNewsLayoutModel)sendMailModel.MailingModel.LayoutModel;
        var targetGroupNames = sendMailModel.MailingModel.MailingLists.Select(p => p.Key).ToList();
        var url = await _linkHelper.CreateUrlFromLinkModelAsync(goodNewsLayout.Url, true);
        var layoutVariables = new[]
        {
            new LayoutVariable("subject", goodNewsLayout.Subject ?? ""),
            new LayoutVariable("text", goodNewsLayout.Text ?? ""), new LayoutVariable("url", url?.ToString() ?? "")
        };

        return new ConvertSendMailResult
        {
            Success = true,
            ProviderModel = new XCampaignSendMailModel([new LocalizedString(goodNewsLayout.Subject!)])
            {
                MailshotName = sendMailModel.MailingModel.Name,
                MailshotForeignId = goodNewsLayout.MailshotForeignId,
                TargetGroupNames = targetGroupNames,
                LayoutVariables = layoutVariables
            }
        };
    }

    public Task<ConvertSendTestMailResult> ConvertAsync(SendTestMailModel sendTestMailModel)
    {
        //not yet supported
        throw new NotImplementedException();
    }
}

  1. Register your layout model and converter in your module.

public void AddModule(IModuleContext module)
{
    module.Configure.RegisterMailingLayout<GoodNewsLayoutModel, MailingLayoutConverter>("Good-news Mailing")
        .Editor(form => form.AddTab(tab =>
        {
            tab.AddInput(p => p.MailshotForeignId);
            tab.AddInput(p => p.Subject)
                .Validate(v => v!.NotEmpty());
            tab.AddInput(p => p.Text)
                .Validate(v => v!.NotEmpty());
            tab.AddConfinityContent(p => p.Url);
        }));
}

Prev
Mail Module
Next
MediaPlayer Module