Posted on 19/01/2024 10:56:52
Hi Andreas,
If you want to use a custom implementation for sending bulk emails (newsletters) within the Marketing section then you need to implement a class that inherits from Dynamicweb.Mailing.MessageDeliveryProvider.
For other emails you can use a notification subscriber to either modify messages or completely override the sending of messages...
using Dynamicweb.Extensibility.Notifications;
using Dynamicweb.Mailing.Notifications;
using System;
using System.Net.Mail;
[Subscribe(EmailNotifications.OnBeforeEmailSend)]
public class EmailNotificationSubscriber : NotificationSubscriber
{
public override void OnNotify(string notification, NotificationArgs args)
{
var emailArgs = (EmailSendNotificationArgs)args;
var message = emailArgs.Message;
// TODO: Modify the message?
emailArgs.IsHandled = true; // prevents the standard email handler from sending the email
emailArgs.WasSent = SendMessage(message);
}
private bool SendMessage(MailMessage message)
{
try
{
// TODO: Send the message
return true;
}
catch
{
return false;
}
}
}