Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Programmatically distribute email campaign activities in CRM using an email template

Posted on by Microsoft Employee

Hi, 

How can we programmatically create campaign acivities of type Email from a email template containing. I need to know how to personalize the email reading the custom HTML in the email template and then create an email type Campaign activity of that email and then distribute it. 

Need assistance. 

Thanks,

*This post is locked for comments

  • Suggested answer
    Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: Programmatically distribute email campaign activities in CRM using an email template

    Hi Fahad,

    You can do with "DistributeCampaignActivityRequest" SDK message and have to provide "TemplateId" data in your request message.

    Your code block should be like this

    DistributeCampaignActivityRequest request = new DistributeCampaignActivityRequest()
    {
       CampaignActivityId = id,
       Activity = activityEntity,
       Owner = new EntityReference("owner entity name", ownerId),
       OwnershipOptions = propagationOwnershipOptions,
       PostWorkflowEvent = useAsync,
       Propagate = doesPropagate,
       SendEmail = sendEmail,
       TemplateId = templateId
    };


    You can also use my helper library (XrmLibrary) and do it simply with 2 lines code like that

    CampaignActivityHelper helper = new CampaignActivityHelper(_organizationService);
    helper.DistributeByEmail(Guid.Parse("Campaign Activity Id"), FromEntityType.SystemUser, Guid.Parse("From Systemuser Id"), "Subject", "Body", Guid.Parse("Email Template Id"), true, PropagationOwnershipOptions.ListMemberOwner, PrincipalType.SystemUser, Guid.Parse("Owner Id"), null);



    Please take a look at https://github.com/emregulcan/xrmlibrary.2016/blob/master/XrmLibrary.EntityHelpers/Marketing/CampaignActivityHelper.cs#L336-L388 or https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.distributecampaignactivityrequest(v=crm.7).aspx for parameter description

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