Question Status

Verified
roubachof asked a question on 2 Jul 2014 12:34 AM

I have a string field containing email addresses separated by ';'.

In the PreEmailSendFromTemplate, I am trying to add these emails to the 'Cc' field of the email to be send.

Here is the code:

IPluginExecutionContext context = localContext.PluginExecutionContext;
Entity targetEntity = (Entity)context.InputParameters["Target"];
Email email = targetEntity.ToEntity<Email>();

if (email.RegardingObjectId != null)
{
    using (var entityContext = new MultimediaContext(localContext.OrganizationService))
    {
        var relatedIncident = entityContext.IncidentSet.FirstOrDefault((incident) => incident.Id == email.RegardingObjectId.Id);
        if (relatedIncident != null && !string.IsNullOrWhiteSpace(relatedIncident.rte_ContactCopie))
        {
            List<ActivityParty> parties = new List<ActivityParty>();
            foreach (var emailAddress in relatedIncident.rte_ContactCopie.Split(';'))
            {
                parties.Add(
                    new ActivityParty
                    {
                        AddressUsed = emailAddress,
                        // ActivityId = new EntityReference(Email.EntityLogicalName, email.ActivityId.Value),
                        ParticipationTypeMask = new OptionSetValue(3)
                    });
            }

            email.Cc = parties;
        }
    }
}

The parties list is well filled with the wanted email addresses.

But unfortunately, the email is never send (not even to the 'To' field members).

When I comment out all this section, the email is sent.

Reply
Peter72 responded on 2 Jul 2014 2:02 AM

Have you set System Settings accordingly? (Allow messages with unresolved e-mail recipients to be sent).

Details and a working sample can be found here:

worldofdynamics.blogspot.ch/.../dynamics-crm-2011-c-code-for-sending.html

Reply
roubachof responded on 2 Jul 2014 2:07 AM

Yes I have.

Note that I am setting the parties in the pre-send operation of the email entity, I am not creating an email from scratch.

Reply
Peter72 responded on 2 Jul 2014 2:46 AM

Do you have any error-message?

Reply
roubachof responded on 2 Jul 2014 9:15 AM

Looking in my system tasks, I can see this error from the failing workflow:

Plugin Trace:

[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.SendEmailFromTemplate]

[SendEmailStep7: Envoyer l'email from support Documat ]

[CrmRte.Multimedia.Plugins: CrmRte.Multimedia.Plugins.PreEmailSendFromTemplate]

[daff4116-dbfd-e311-93fe-00155d03036f: PreEmailSendFromTemplate]

Error Message:

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Runtime.Serialization.SerializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #AF542EAEDetail:

<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">

 <ErrorCode>-2147220970</ErrorCode>

 <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />

 <Message>System.Runtime.Serialization.SerializationException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #AF542EAE</Message>

 <Timestamp>2014-07-02T16:07:11.1110682Z</Timestamp>

 <InnerFault i:nil="true" />

 <TraceText>[Microsoft.Xrm.Sdk.Workflow: Microsoft.Xrm.Sdk.Workflow.Activities.SendEmailFromTemplate]

[SendEmailStep7: Envoyer l'email from support Documat ]

[CrmRte.Multimedia.Plugins: CrmRte.Multimedia.Plugins.PreEmailSendFromTemplate]

[daff4116-dbfd-e311-93fe-00155d03036f: PreEmailSendFromTemplate]

</TraceText>

</OrganizationServiceFault>

  at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType)

  at Microsoft.Crm.Extensibility.InprocessServiceProxy.ExecuteCore(OrganizationRequest request)

  at Microsoft.Crm.Workflow.Services.SendEmailFromTemplateActivityService.<>c__DisplayClass1.<SendEmailFromTemplateInternal>b__0(IOrganizationService sdkService)

  at Microsoft.Crm.Workflow.Services.ActivityServiceBase.ExecuteInTransactedContext(ActivityDelegate activityDelegate)

  at Microsoft.Crm.Workflow.Services.SendEmailFromTemplateActivityService.SendEmailFromTemplateInternal(Entity emailEntity, Guid regardingId, String regardingType, Guid templateId)

  at Microsoft.Crm.Workflow.Services.SendEmailFromTemplateActivityService.ExecuteInternal(ActivityContext executionContext, SendEmailFromTemplate sendEmailFromTemplate)

  at Microsoft.Crm.Workflow.Services.SendEmailFromTemplateActivityService.Execute(ActivityContext executionContext, SendEmailFromTemplate sendEmailFromTemplate)

  at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)

  at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Reply
Verified Answer
Aileen Gusni responded on 2 Jul 2014 10:19 AM

Hi, do you register your plugin in sandbox?

Please refer to this link:

benpatterson1.blogspot.com/.../crm-2011-activity-party-and.html

Thank you.

Reply
roubachof responded on 2 Jul 2014 3:29 PM

GREAT !

Thank you, I switch back to non isolated as I didn't really need it.

I was just trying to have good security practice, but this isolated mode is finally too painful.

Reply
Verified Answer
Aileen Gusni responded on 2 Jul 2014 10:19 AM

Hi, do you register your plugin in sandbox?

Please refer to this link:

benpatterson1.blogspot.com/.../crm-2011-activity-party-and.html

Thank you.

Reply