Copied to clipboard

Flag this post as spam?

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


  • jonas-jaderberg 7 posts 47 karma points
    Aug 20, 2022 @ 08:32
    jonas-jaderberg
    0

    Exception when sending email with templateService

    Hi,

    I upgraded Vendr to latest, 2.3.3 from 2.2.0. Now I cannot send confirmation emails. I am using the templateService.SendEmail method to generate and send emails. The code looks like this

      var template = _templateService.GetEmailTemplate(store.Id, "configEmail"); 
                     _templateService.SendEmail(template, order, model.EmailAddress, "");
    

    I call it from a controller. The email is rendered just fine, but when the email is sent an exception is thrown

    An asynchronous operation cannot be started at this time. Asynchronous operations may only be started within an asynchronous handler or module or during certain events in the Page lifecycle. If this exception occurred while executing a Page, ensure that the Page is marked <%@ Page Async="true" %>.

    This is the stack trace

    vid System.Net.Mail.SmtpClient.SendAsync(MailMessage message, Object userToken)    vid System.Net.Mail.SmtpClient.SendMailAsync(MailMessage message)    vid Umbraco.Core.EmailSender.<SendAsync>d__5.MoveNext() i D:\a\1\s\src\Umbraco.Core\EmailSender.cs:rad 74
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---    vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    vid Vendr.Core.Pipelines.Email.Tasks.SendEmailTask.<>c__DisplayClass2_0.<<Execute>b__0>d.MoveNext()
    --- Slut på stackspårningen från föregående plats där ett undantag utlöstes ---    vid System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()    vid System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)    vid Vendr.Common.Helpers.AsyncHelper.RunSync(Func`1 func)    vid Vendr.Core.Pipelines.Email.Tasks.SendEmailTask.Execute(EmailSendPipelineArgs args)    vid Vendr.Common.Pipelines.InProcPipelineInvoker.<Vendr.Common.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )    vid Vendr.Common.Pipelines.InProcPipelineInvoker.Vendr.Common.Pipelines.IP ipelineInvoker.Invoke(IEnumerable`1 pipelineTasks, PipelineArgs args)  vid Vendr.Common.Pipelines.Pipeline.Invoke[TPipeline,TArgs,TEntity](Func`2 argsFactory)    vid Vendr.Core.Services.EmailTemplateService.SendEmail[TModel](EmailTemplateReadOnly emailTemplate, TModel model, String toEmailAddress, String languageIsoCode)    vid Leksandsdorren.Core.Controllers.CartSurfaceController.SendEmailFromCart(CartEmailViewModel model)
    

    Any ideas?

    Best regards, Jonas Jäderberg

  • jonas-jaderberg 7 posts 47 karma points
    Aug 20, 2022 @ 13:12
    jonas-jaderberg
    0

    I did some more test and if I change my controller method to

    public async Task<ActionResult> SendEmailFromCart(CartEmailViewModel model)
    

    Making it asyncronus I get rid of the exception but the call to _templateService.SendEmail just hangs forever.... but the email is sent.

  • jonas-jaderberg 7 posts 47 karma points
    Aug 22, 2022 @ 05:35
    jonas-jaderberg
    0

    Hi again,

    I reverted back to Vendr 2.3.0 and now I can send email again. So there must be an issue introduced in a version never then 2.3.0.

    Jonas Jäderberg

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

    Hi Jonas,

    I think I came across this too. It appears to be a problem around our AsyncHelper that is used to run some async code sycronously. We changed it becasue it caused another problem elsewhere but clearly it has had a regression.

    If you'd like to test, there is a new 2.3.4-beta0009 on our unstable NuGet feed at https://nuget.outfield.digital/unstable/vendr/v3/index.json If you can confirm that this works for you, I'll get an update pushed out.

    Matt

  • jonas-jaderberg 7 posts 47 karma points
    Aug 22, 2022 @ 08:02
    jonas-jaderberg
    0

    I can confirm that 2.3.4-beta0009 works for me.

    Jonas

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

    Perfect! I'll get that published today

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Aug 22, 2022 @ 08:27
    Matt Brailsford
    100

    That's just been published now 👍

Please Sign in or register to post replies

Write your reply to:

Draft