Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

Add activity parties to email before send (plugin CRM 2011)

$
0
0

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.


Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>