Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tor Langlo 191 posts 554 karma points
    Feb 25, 2023 @ 01:23
    Tor Langlo
    0

    EmailSendingNotification - is it possible to prevent further processing (e-mail sending)

    We have our own e-mail sending code which we trigger from inside the EmailSendingNotification's Handle() method, and would like to stop Vendr from continuing with its own e-mail sending process at this point. Is that possible? E.g. a "Cancel" property or similar in the EmailSendingNotification class would be convenient.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Feb 27, 2023 @ 09:05
    Matt Brailsford
    100

    Hey Tor,

    Rather than hooking into the EmailSendingNotification you'd probably be better off replacing the SendEmailTask pipeline task that is used as part of the send email pipeline.

    This is the current pipeline task code

    public class SendEmailTask : PipelineTaskWithTypedArgsBase<EmailSendPipelineArgs, EmailContext>
    {
        private readonly IEmailSender _emailSender;
        private readonly ILogger<SendEmailTask> _logger;
    
        public SendEmailTask(IEmailSender emailSender,
            ILogger<SendEmailTask> logger)
        {
            _emailSender = emailSender;
            _logger = logger;
        }
    
        public override PipelineResult<EmailContext> Execute(EmailSendPipelineArgs args)
        {
            AsyncHelper.RunSync(() => _emailSender.SendAsync(args.Model.MailMessage));
    
            return Ok(args.Model);
        }
    }
    

    So you could tweak that to do what you need to do then check the docs here for working with pipelines https://vendr.net/docs/core/3.0.0/key-concepts/pipelines/ You'll want to call Replace<SendEmailTask, MySendEmailTask>() to swap the implementation.

    Hope this helps

  • Tor Langlo 191 posts 554 karma points
    Feb 27, 2023 @ 23:59
    Tor Langlo
    0

    Ok, thanks! I started doing this over the weekend, and this confirmed my approach.

  • Nick Hoang 51 posts 180 karma points c-trib
    Apr 13, 2023 @ 01:54
    Nick Hoang
    0

    Hi Matt,

    I'm using vendr 1.8.6 and this line of code doesn't work:

    composition.WithSendEmailPipeline().Replace<SendEmailTask, MySendEmailTask>();            
    

    The SendEmailTask doesn't exist. Could you correct it for me?

    Thanks, Nick

  • Nick Hoang 51 posts 180 karma points c-trib
    Apr 13, 2023 @ 04:28
    Nick Hoang
    1

    I figure it out, this works for vendr version 1.8.6:

    composition.WithSendEmailPipeline().Replace<SendSmtpEmailTask, MySendEmailTask>();
    

    Cheers

Please Sign in or register to post replies

Write your reply to:

Draft