Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Suggested answer

Error sending email

Posted on by 10

I am trying to send an email on update of the queueItem entity using pluginEventContext.GetOrgService(userId). 

*** Side question here, what is the difference between using that and using  pluginEventContext.XrmContext.OrgService? But I tried both and same error.

An exception has occurred in the [CSF.Xrm.Plugins.QueueItem.SendEmailPlugin].\nAn unhandled organization service fault occurred during execution of the plugin.\n{System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=]]} from {Microsoft.CDSRuntime.SandboxWorker} - Entity 'Contact' With Id = 74f7aff7-50e7-ed11-a7c6-002248081803 Does Not Exist

Notice that the id on the error, it is the same as the regardingobjectid. But the type of object is queueItem not contact. 

This is what is being sent to service.Create(email):

{"LogicalName":"email","Id":"00000000-0000-0000-0000-000000000000","Attributes":[{"Key":"from","Value":[{"LogicalName":"activityparty","Id":"00000000-0000-0000-0000-000000000000","Attributes":[{"Key":"partyid","Value":{"Id":"2f9953be-882c-ed11-9db1-000d3a334aeb","LogicalName":"systemuser","Name":null,"KeyAttributes":[],"RowVersion":null}}],"EntityState":null,"FormattedValues":[],"RelatedEntities":[],"RowVersion":null,"KeyAttributes":[]}]},{"Key":"to","Value":[{"LogicalName":"activityparty","Id":"00000000-0000-0000-0000-000000000000","Attributes":[{"Key":"partyid","Value":{"Id":"241e8a77-1b59-ec11-8f8f-002248083b75","LogicalName":"systemuser","Name":null,"KeyAttributes":[],"RowVersion":null}}],"EntityState":null,"FormattedValues":[],"RelatedEntities":[],"RowVersion":null,"KeyAttributes":[]}]},{"Key":"subject","Value":"Letter from Unassigned - SSN: Unassigned - UMI: Unassigned Assigned"},{"Key":"description","Value":"">mycompany-dev.crm.dynamics.com/.../main.aspx"Key":"regardingobjectid","Value":{"Id":"74f7aff7-50e7-ed11-a7c6-002248081803","LogicalName":"queueitem","Name":null,"KeyAttributes":[],"RowVersion":null}}],"EntityState":null,"FormattedValues":[],"RelatedEntities":[],"RowVersion":null,"KeyAttributes":[]}.

public static bool Send(Guid fromPartyId , Guid toPartyId, Entity entity, Guid entityId, string subject, string body, IOrganizationService service, ILogger logger)
{

var email = new Entity("email");


var toParty = new Entity("activityparty")
{
["partyid"] = new EntityReference("systemuser", toPartyId) // target
};

var fromParty = new Entity("activityparty")
{
["partyid"] = new EntityReference("systemuser", fromPartyId) //pre
};

email["from"] = new[] { fromParty };

email["to"] = new[] { toParty };
email["subject"] = subject;
email["description"] = body;

email["regardingobjectid"] = entity.ToEntityReference();
logger.LogInformation($"email: {JsonConvert.SerializeObject(email)}");
var emailId = service.Create(email);

var sendEmailRequest = new SendEmailRequest
{
EmailId = emailId,
//TrackingToken = "",
IssueSend = true
};

var response = (SendEmailResponse)service.Execute(sendEmailRequest);
logger.LogInformation(JsonConvert.SerializeObject(response));
return true;

}
}

  • Suggested answer
    svetochka18 Profile Picture
    svetochka18 10 on at
    RE: Error sending email

    So it turns out that activities ("letter", "fax", etc) can not be used as regardingobjectid.  I tried updating the record in SQL 4 CDS and got an error with a list of entities.  Activities are not included.

    My guess is that "contact" is the default in the API. So that is why it kept erroring out with "contact" Does Not Exist.

    When I changed to incident, it worked.

      email["regardingobjectid"] = new EntityReference("incident", new Guid("65ef456b-15c8-ed11-b597-002248081c87"));

    Perhaps that is something that can be configured?

  • svetochka18 Profile Picture
    svetochka18 10 on at
    RE: Error sending email
    [quote user="Xavier Monin"]

    Hi,

    You try to set the regardingobjectid to a queueitem. Queueitem does not allow to be targeted by a regardingobjectid.

    pastedimage1683117395346v1.png

    You probably want to set the regardingobjectid to the objectid of the queue item ?

    [/quote]

    FYI: objectid is the letterid not queueid

    Tried setting regardingobjectid to

              email["regardingobjectid"] = new EntityReference("letter", objectid ); //postQueueItem.objectid 
    Also tried: 
              email["regardingobjectid"] = entityRef;//_postQueueItem.id -  Logical name: queueItem, id: queueitem.id


    Still the same error. it is trying to connect that id to contact 


  • Suggested answer
    XM-22040801-0 Profile Picture
    XM-22040801-0 11 on at
    RE: Error sending email

    Hi,

    You try to set the regardingobjectid to a queueitem. Queueitem does not allow to be targeted by a regardingobjectid.

    pastedimage1683117395346v1.png

    You probably want to set the regardingobjectid to the objectid of the queue item ?

  • Suggested answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Error sending email

    Hello,

    I believe the error talks for itself - record you try to pass to regardingobjectid field doesn't exist in the environment. Trace back in your plugin where it comes from.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans