Developer forum

Forum » CMS - Standard features » Override built-in mailsending function

Override built-in mailsending function

Andreas Pettersson
Reply

Hi,

Is there any way you can override DW's built in mail sending functionality? Our customer wants to have some new security on email sending and send on a specific way but we using for example Extranet app for restore password and that mail goes through standard built in mail functionality.

We have a custom mail method for different types of email from our site which we can change but dont know if i can override DW built in?

Regards
Andreas 


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

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;
        }
    }
}
Votes for this answer: 1
 
Andreas Pettersson
Reply

Hi,
Thank you for the information. Looks simple to use.

Regards

Andreas

 

You must be logged in to post in the forum