Try our conversational search powered by Generative AI!

Episerver Forms: object instance not set to an instance of an object when sending email

Vote:
 

Hi!

We are running the following setup for Optimizely Forms in our clients solution:

EPiServer.Forms 5.7.1
EPiServer.Forms.Samples 4.2.2

When we define our forms with a Send email actor in the editorial part of the form and submit a successfull form submission, we receive the following in the logs:
 

{"Timestamp":"2023-11-29T07:25:18.6347814+01:00","Level":"Error","MessageTemplate":"{State:l}","Exception":"System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)\r\n ---> System.NullReferenceException: Object reference not set to an instance of an object.\r\n   at EPiServer.Notification.Internal.SmtpClientImplementation.SendAsync(MimeMessage message)\r\n   --- End of inner exception stack trace ---\r\n   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)\r\n   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)\r\n   at System.Threading.Tasks.Task.Wait()\r\n   at EPiServer.Forms.Implementation.Actors.SendEmailAfterSubmissionActor.<>c__DisplayClass13_0.<SendMessage>b__3()","Properties":{"State":"Failed to send email","SourceContext":"EPiServer.Forms.Core.PostSubmissionActor.PostSubmissionActorBase","ActionId":"b63041e0-adba-4e2a-abd6-70c87415f975","ActionName":"EPiServer.Forms.Controllers.DataSubmitController.Submit (EPiServer.Forms)","RequestId":"0HMVGKFJQTH3F:00000009","RequestPath":"/EPiServer.Forms/DataSubmit/Submit","ConnectionId":"0HMVGKFJQTH3F"},"Renderings":{"State":[{"Format":"l","Rendering":"Failed to send email"}]}}

The internal controller for sending an email seems to fail within Optimizely.  

This is the following configuration we have for the Smtp config for the solution:

    "Smtp": {
      "DeliveryMethod": "Network",
      "SpecifiedPickupDirectory": "C:\\Episerver\\SmtpMail",
      "Network": {
        "Host": "smtp.sendgrid.net",
        "Port": "587",
        "UserName": "mykeyhere",
        "Password": "mypasswordhere",
        "UseSsl": true
      },
      "Notification": {
        "NotificationEmailDisplayName": "Optimizely Notification",
        "NotificationEmailAddress": "cms@optimizely.com"
      }
    },
    "Forms": {
      "FormsConfig": {
        "VisitorSubmitTimeout": 1,
        "DisableFormCookies": false,
        "DataExportBlobProviderName": "DefaultDataExportBlobProvider",
        "SerializingObjectUsingNameValueFormat": true,
        "SendMessageInHTMLFormat": true,
        "MinimumAccessRightLevelToReadFormData": "Edit",
        "CoreController": "/EPiServer.Forms/DataSubmit",
        "DefaultUploadExtensionBlackList": "asp,aspx,asa,ashx,asmx,bat,chm,class,cmd,com,config,dll,exe,hta,htr,htw,jse,json,lnk,mda,mdb,msc,msh,pif,printer,ps1,ps2,reg,rem,scf,scr,sct,shtm,shtml,soap,stm,svc,url,vb,vbe,vbs,vsix,ws,wsc,wsf,wsh,xamlx,htm,html,js,jar",
        "FormElementViewsFolder": "~/Views/Shared/ElementBlocks",
        "WorkInNonJSMode": false,
        "InjectFormOwnStylesheet": true,
        "InjectFormOwnJQuery": true,
        "RenderingFormUsingDivElement": false
      },
      "FormsPermanentStorageProvider": {
        "DefaultProvider": "DdsPermanentStorage",
        "Providers": {
          "DdsPermanentStorage": {
            "Type": "EPiServer.Forms.Core.Data.DdsPermanentStorage, EPiServer.Forms.Core",
            "Parametters": {}
          }
        }
      }
    }

Have we missed something in the configuration sections or is this an internal bug for the latest Forms?

Regards
Eric

#313335
Nov 29, 2023 6:31
Vote:
 

Could you debug your site and turn off the "Just my code" option? that would give a pretty good idea of what is null.

Looked quickly and it seems your settings and the code that send stmp mails are both correct

#313337
Nov 29, 2023 8:01
Vote:
 

Hi Quan

I received the following exceptions while posting the form without Just my code enabled: the exception is thrown at System.Threading.Tasks and is missing the SmtpClientImplementation.cs... is this file somehow related in the nuget package of Forms?

Regards
Eric

#313344
Nov 29, 2023 11:29
Vote:
 

Yeah try to decompile. It is not great but you can probably get what is null. 

What is your exact version, I might be able to grab you a pdb 

#313346
Nov 29, 2023 11:54
Vote:
 

Seems to not be able to Decompile? Now I receive this SendEmailAfterSubmissionActor.cs not found

#313352
Nov 29, 2023 12:51
Vote:
 

I decompiled with IlSpy and hence cannot find the assembly path for the SendEmailAfterSubmissionActor at EPiServer.Forms.Implementation.Actors

#313354
Nov 29, 2023 13:26
Vote:
 

No you should only need SmtpClientImplementation - as it's throwing exception

#313357
Nov 29, 2023 14:45
Vote:
 

SmtpClientImplementation is not thrown any longer, only SendEmailAfterSubmissionActor now - is this actor still referred in the EPiServer.Forms.Implementation.Actors namespace?

Or could we be having something else mismatch in our solution?

#313358
Nov 29, 2023 15:31
Vote:
 

Turned out that is was a missconfiguration in the appsettings.json for the internal smtp section of the application...

Silly of me to not notice this

#313645
Dec 04, 2023 8:53
Quan Mai - Dec 06, 2023 12:18
it happens (to any of us) more than we'd like to admit :)
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.