web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin that sends an email throws error only for some users.

(0) ShareShare
ReportReport
Posted on by

Hi All,

I'm at my wits end with this issue and hence the post. I have a plugin that runs on the Update message for an entity. The plugin does some stuff and at the end sends an email. I have trace code throughout the plugin which shows that the code executes all the way down to this line below and then throws an error.

localContext.Trace("SendEmailResponse Object initialised.");

// The above line can be seen in the stack trace so its the line below that errors.
SendEmailResponse sendEmailResp = (SendEmailResponse)localContext.OrganizationService.Execute(sendEmailReq);


Stack Trace for the error is... 

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Object reference not set to an instance of an object.Detail:
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
  <ErrorCode>-2147220891</ErrorCode>
  <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic">
    <KeyValuePairOfstringanyType>
      <d2p1:key>OperationStatus</d2p1:key>
      <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">0</d2p1:value>
    </KeyValuePairOfstringanyType>
    <KeyValuePairOfstringanyType>
      <d2p1:key>SubErrorCode</d2p1:key>
      <d2p1:value xmlns:d4p1="www.w3.org/.../XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
    </KeyValuePairOfstringanyType>
  </ErrorDetails>
  <Message>Object reference not set to an instance of an object.</Message>
  <Timestamp>2017-11-23T12:57:27.2141815Z</Timestamp>
  <InnerFault i:nil="true" />
  <TraceText>
 
[ePermits.Plugins: ePermits.Plugins.PostElectricalStandingInstructionUpdate]
[524be194-51a3-e711-80da-001dd8b71dde: PostElectricalStandingInstructionUpdate]
Entered ePermits.Plugins.PostElectricalStandingInstructionUpdate.Execute(), Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
ePermits.Plugins.PostElectricalStandingInstructionUpdate is firing for Entity: cal_electricalstandinginstruction, Message: Update, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Passed plugin registration checks., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
AE and owner Id column value successfully retrieved., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Authorising Engineer is not null and is :Another User, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Access Granted, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
AE GUID:e9ee81a8-16a4-e711-80da-001dd8b71dde, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Created activity parties., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Email Created., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
ec70afda-4dd0-e711-80dc-001dd8b71dde, Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
SendEmailResponse Object initialised., Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde
Exiting ePermits.Plugins.PostElectricalStandingInstructionUpdate.Execute(), Correlation Id: e0bbdf02-8e62-413b-b7bc-e6dc851c41f0, Initiating User: c91f3afb-e871-e711-80d8-001dd8b71dde


Now strangely enough if I select in Email To:  a user that is Sys Admin, then this code runs without error but if I select a user who is not sys admin then it errors with the error above. So I'm confident that this error is related to security roles of the Email To user. However, without a clear error message I dont know which security role setting I need to change which will solve this problem. Any ideas?

*This post is locked for comments

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    Hi,

     how are you initializing sendEmailReq? Maybe there is something there..

  • Community Member Profile Picture
    on at

    SendEmailRequest sendEmailReq = new SendEmailRequest

    {

    EmailId = _emailGuid,

    TrackingToken = "",

    IssueSend = true

    };

  • Community Member Profile Picture
    on at

    Hi leylandtalks,

    Please post all plugin code.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Everyone,

    Thanks for your attempts to help. I've now found out what was causing this error and thought I'd update this thread incase it helps anyone else with the same problem. Thanks to Alex who suggested I investigate the SendEmailRequest object. I decided to trace all the variables I was using in that object. So I traced the Subject and Body values and noticed that the Subject was going over two lines suggesting a new line carriage return being introduced into it somehow. The variable was a string variable into which I was saving the serial number of the record. For example. Each record that I created was assigned a reference no. SP25. I was using a workflow to generate this number. In the workflow screen, I would type in the letters 'SP' and then use the UI to pick the number 25 from a increment variable and add it to the SP text. What I noticed is that the CRM UI adds a newline character to the textbox. The record reference was therefore CRLFSP25 instead of SP25. So there... now you know it. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans