Copied to clipboard

Flag this post as spam?

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


  • Philip Hayton 98 posts 435 karma points
    Sep 21, 2022 @ 10:32
    Philip Hayton
    0

    Unable to send emails using custom pipeline in RC3.0.0-rc0050

    Hi Matt,

    We are using a custom pipeline task to send emails via the SendGrid API, which worked fine in the previous version but is throwing an error in the RC. I am registering the pipeline task in startup like so:

    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddUmbraco(_env, _config)
            .AddBackOffice()
            .AddWebsite()
            .AddComposers()
            .AddVendr(builder =>
            {
                builder.WithSendEmailPipeline().Remove<RenderEmailTemplateTask>();
                builder.WithSendEmailPipeline().Replace<SendEmailTask, SendEmailWithSendGridTask>();
            })
            .Build();
    }
    

    I've pasted the error below, it looks like the default email send task is being hit even though I've replaced it.

    Any ides what I'm doing wrong?

    at Vendr.Infrastructure.Resiliency.PollyExecutionStrategyBase.Execute[TResult](Func`1 operation, Func`1 verifySucceeded)
       at Vendr.Core.Services.EmailTemplateService.SendEmail[TModel](EmailTemplateReadOnly emailTemplate, TModel model, String toEmailAddress, String languageIsoCode)
       at Vendr.Umbraco.Web.Controllers.VendrEmailController.SendEmail[TModel](SendEmailDto cfg, OrderReadOnly order, TModel model)
       at Vendr.Umbraco.Web.Controllers.VendrEmailController.SendOrderEmail(SendOrderEmailDto dto)
       at lambda_method1482(Closure , Object , Object[] )
       at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
       at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
    --- End of stack trace from previous location ---
       at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
    
  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 21, 2022 @ 12:45
    Matt Brailsford
    0

    Hmm, nothing in the stack trace suggests it's running the default send task as it's the EmailTemplateService that triggers the pipeline. Unfortunately that stack trace isn't giving much away as to what is actually erroring 🤔

    I'm guessing this doesn't actually hit any breakpoints in your SendEmailWithSendGridTask?

    PS is there an exception message that goes along with that stack trace? I'm not exactly sure what it's erroring over.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 22, 2022 @ 07:58
    Matt Brailsford
    0

    Just to follow up on this, this morning I thought I'd just test swapping out tasks and so implemented exactly what you've presented here, inside a vendr builder removing a task and replacing a task with an alternative implementation and for me it worked as expected.

    The removed / replaced tasks don't get hit via a breakpoint, but the replacement task does. If I cause my replacement task to throw an exception, it does throw something similar to what you were seeing (though not a 100% match) so it could still be an issue within your replacement task.

  • Philip Hayton 98 posts 435 karma points
    Sep 22, 2022 @ 08:04
    Philip Hayton
    0

    Hi Matt,

    Thanks for investigating, ok I'll do some more digging it could be that something is throwing an obscure error somewhere that's not being caught.

  • Philip Hayton 98 posts 435 karma points
    Sep 22, 2022 @ 09:33
    Philip Hayton
    0

    Hi Matt,

    Ok I've got a bit more info for you.

    So the error is actually caused when the Template View field on an Email Template doesn't resolve to a physical razor template. For example a typo will cause this error.

    enter image description here

    For most use cases this is probably desirable, although maybe a friendlier error could be thrown, but in my case I actually use that field to define the TemplateID for the Send Grid email template.

    enter image description here

    In the previous version this approach works without issue. Is there anything in V3 that would cause this issue and is there anyway to circumvent it?

    Also as a side note I noticed that errors thrown during email pipelines are not logged to the Umbraco log by default, is that intentional?

    Thanks again for your time. 🙏🏻

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 22, 2022 @ 10:14
    Matt Brailsford
    0

    Hmmm, the only place that uses that property though is the RenderEmailTemplateTask so I wouldn't expect the pipeline to throw an exception if the task had been removed 🤔

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 22, 2022 @ 10:19
    Matt Brailsford
    100

    Actually, I think I may know what it is.

    You are calling AddVendr after AddComposers, but Vendr has a default composer to add vendr if it hasn't already been added and so by the time you call AddVendr vendr has already been added and so escapes without modifying the config, and so non of your changes are being applied.

    Check the docs here and you'll see it should be called before AddComposers https://vendr.net/docs/core/3.0.0/key-concepts/vendr-builder/

  • Philip Hayton 98 posts 435 karma points
    Sep 22, 2022 @ 12:24
    Philip Hayton
    0

    Hi Matt,

    You're absolutely right, that was the issue.

    I actually put the AddVendr call after AddComposers conciously as my pipeline depended on a few services I thought needed to be register first. But a few simple changes and it's back to working as expected again. 👍🏻

    Thanks for your help!

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Sep 22, 2022 @ 13:36
    Matt Brailsford
    0

    Perfect!

    Glad it's up and working.

    I was holding off releasing v3 incase this was a bug so I can get that out the door now too 🥳

Please Sign in or register to post replies

Write your reply to:

Draft