Copied to clipboard

Flag this post as spam?

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


  • Morten 'Nasmar' Bjergø 9 posts 99 karma points
    Mar 03, 2023 @ 12:30
    Morten 'Nasmar' Bjergø
    0

    Vendr send email error in OrderTransactionUpdatedHandler

    Hi,

    I sometimes get this error, when trying to send an email confirmation to our customers. Message: Value cannot be empty. (Parameter 'body')".

    Its fails like 5% of the time we send mails. When we afterwards resend the email, it doesn't fail.

    I have tried to log out the email template and the template view, and they both seem correct. The template view is a dictionary, to use two different languages (We have one cshtml for english and another for our native language). Both templates works when tested.

    Umbraco version 9.5.4

    Vendr 2.3.4

    My code is the following - I run this in the OrderTransactionUpdatedHandler when and order changes to PaymentStatus: Captured ( if (evt.PaymentStatus.To.Value == Vendr.Core.Models.PaymentStatus.Captured) )

                    var order = _vendrApi.GetOrder(orderId);
                    var stores = _vendrApi.GetStores();
                    var store = _vendrApi.GetStore(stores.FirstOrDefault().Id);
    
                    IEnumerable<EmailTemplateReadOnly> templates = VendrApi.Instance.GetEmailTemplates(store.Id);
                    EmailTemplateReadOnly orderInvoiceTemplate = null;
                    foreach (EmailTemplateReadOnly template in templates)
                    {
                        if (template.Name == "Invoice") orderInvoiceTemplate = template;
                    }
    
                    Serilog.Log.Information($"Email template used: {orderInvoiceTemplate?.Id}, templateview was: {orderInvoiceTemplate.TemplateView}");
                    Serilog.Log.Information($"Order Id: {order?.Id}");
    
                    _vendrApi.SendEmail(orderInvoiceTemplate, order);
    

    The error I get:

    {
    "InnerExceptions": [
        {
            "Message": "Value cannot be empty. (Parameter 'body')",
            "ParamName": "body",
            "TargetSite": "Void ArgumentIsNotNullOrEmpty(System.String, System.String)",
            "StackTrace": "   at Umbraco.Cms.Core.Models.Email.EmailMessage.ArgumentIsNotNullOrEmpty(String arg, String argName)\r\n   at Umbraco.Cms.Core.Models.Email.EmailMessage..ctor(String from, String[] to, String[] cc, String[] bcc, String[] replyTo, String subject, String body, Boolean isBodyHtml, IEnumerable`1 attachments)\r\n   at Vendr.Extensions.MailMessageExtensions.ToEmailMessage(MailMessage message)\r\n   at Vendr.Umbraco.Mail.UmbracoEmailSender.SendAsync(MailMessage message)\r\n   at Vendr.Core.Pipelines.Email.Tasks.SendEmailTask.<>c__DisplayClass3_0.<Execute>b__0()\r\n   at Vendr.Common.Helpers.AsyncHelper.<>c__DisplayClass1_0.<<RunSync>b__0>d.MoveNext()",
            "Data": [],
            "InnerException": null,
            "HelpLink": null,
            "Source": "Umbraco.Core",
            "HResult": -2147024809,
            "$type": "ArgumentException"
        }
    ],
    "Message": "AsyncHelper.RunSync method threw an exception. (Value cannot be empty. (Parameter 'body'))",
    "TargetSite": "Void BeginMessageLoop()",
    "StackTrace": "   at Vendr.Common.Helpers.AsyncHelper.ExclusiveSynchronizationContext.BeginMessageLoop()\r\n   at Vendr.Common.Helpers.AsyncHelper.RunSync(Func`1 task)\r\n   at Vendr.Core.Pipelines.Email.Tasks.SendEmailTask.Execute(EmailSendPipelineArgs args)\r\n   at Vendr.Common.Pipelines.Tasks.PipelineTaskWithTypedArgsBase`2.Execute(PipelineArgs`1 args)\r\n   at Vendr.Common.Pipelines.Tasks.PipelineTaskBase`2.Execute(PipelineArgs input)\r\n   at Vendr.Common.Pipelines.InProcPipelineInvoker.<Vendr.Common.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )\r\n   at Vendr.Common.Pipelines.InProcPipelineInvoker.<Vendr.Common.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )\r\n   at Vendr.Common.Pipelines.InProcPipelineInvoker.<Vendr.Common.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )\r\n   at Vendr.Common.Pipelines.InProcPipelineInvoker.<Vendr.Common.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )\r\n   at Vendr.Common.Pipelines.InProcPipelineInvoker.<Vendr.Common.Pipelines.IPipelineInvoker.Invoke>g__next|2_0(PipelineArgs e, <>c__DisplayClass2_0& )\r\n   at Vendr.Common.Pipelines.InProcPipelineInvoker.Vendr.Common.Pipelines.IPipelineInvoker.Invoke(IEnumerable`1 pipelineTasks, PipelineArgs args)\r\n   at Vendr.Common.Pipelines.Pipeline.Invoke[TPipeline,TArgs,TEntity](Func`2 argsFactory)\r\n   at Vendr.Core.Services.EmailTemplateService.SendEmail[TModel](EmailTemplateReadOnly emailTemplate, TModel model, String toEmailAddress, String languageIsoCode)\r\n   at Vendr.Core.Services.EmailTemplateService.SendEmail(EmailTemplateReadOnly emailTemplate, OrderReadOnly order)\r\n   at Vendr.Core.Api.CoreVendrApi.SendEmail(EmailTemplateReadOnly emailTemplate, OrderReadOnly order)\r\n   at AS3.Webshop.Listeners.OrderTransactionUpdatedHandler.SendEmail(Guid orderId) in D:\\a\\1\\s\\src\\AS3.Webshop\\Listeners\\OrderTransactionUpdatedHandler.cs:line 134",
    "Data": [],
    "InnerException": {
        "Message": "Value cannot be empty. (Parameter 'body')",
        "ParamName": "body",
        "TargetSite": "Void ArgumentIsNotNullOrEmpty(System.String, System.String)",
        "StackTrace": "   at Umbraco.Cms.Core.Models.Email.EmailMessage.ArgumentIsNotNullOrEmpty(String arg, String argName)\r\n   at Umbraco.Cms.Core.Models.Email.EmailMessage..ctor(String from, String[] to, String[] cc, String[] bcc, String[] replyTo, String subject, String body, Boolean isBodyHtml, IEnumerable`1 attachments)\r\n   at Vendr.Extensions.MailMessageExtensions.ToEmailMessage(MailMessage message)\r\n   at Vendr.Umbraco.Mail.UmbracoEmailSender.SendAsync(MailMessage message)\r\n   at Vendr.Core.Pipelines.Email.Tasks.SendEmailTask.<>c__DisplayClass3_0.<Execute>b__0()\r\n   at Vendr.Common.Helpers.AsyncHelper.<>c__DisplayClass1_0.<<RunSync>b__0>d.MoveNext()",
        "Data": [],
        "InnerException": null,
        "HelpLink": null,
        "Source": "Umbraco.Core",
        "HResult": -2147024809,
        "$type": "ArgumentException"
    },
    "HelpLink": null,
    "Source": "Vendr.Common",
    "HResult": -2146233088,
    "$type": "AggregateException" }
    

    Any idea what to do about it?

    /Br

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 03, 2023 @ 13:59
    Matt Brailsford
    100

    My initial thought would be to double check your template and make sure there isn't something that might cause an exception whilst rendering. It could be that the template tries to do something that errors and causes setting the message body to fail.

    It might be worth button some kind of logging in your email template to check what causes this. Or even, try and empty email template to see if it fails even with this as if it does, then it would suggest it might be a pipeline issue rather than a template code issue.

  • Morten 'Nasmar' Bjergø 9 posts 99 karma points
    Mar 06, 2023 @ 09:32
    Morten 'Nasmar' Bjergø
    0

    Hi Matt,

    Thank you for your respond.

    I will try to check both our templates - I think we only use stuff from the order - but I will see if we can setup checks etc. - so that it may not fail - if properties etc. is missing.

    We can't really run with an empty email template in production. I cannot reproduce the error in our test environments and as I said it only happens in like 5-10% of email send outs.

    But I will see if we can put some logging in our email templates.

  • Morten 'Nasmar' Bjergø 9 posts 99 karma points
    Mar 27, 2023 @ 09:45
    Morten 'Nasmar' Bjergø
    0

    Just if anyone else gets this problem.

    It seems that settings checks up on everything regarding the order in the template did the trick.

    I have not seen email errors since I sorted it out ( Over a week ago).

    I will mark it as solved!

Please Sign in or register to post replies

Write your reply to:

Draft