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.
- 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; }
}
- Implement a
IMailingModelConverterfor your model that creates a provider specific model. In the example, XCampaingn was chosen with theXCampaignSendMailModel.
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();
}
}
- 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);
}));
}