Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Custom Workflow activity/Plugin to send Email to a recipient not in CRM

Posted on by 330

I have a requirement to send email to recipients not in crm.

That is not a look up to the party activity entity ..how can this be achieved the  current code only allows a look up

		Guid fromID = context.UserId;
		Entity sendEmail = new Entity("email");

		Entity fromReciepent = new Entity("activityparty");
		fromReciepent["partyid"] = new EntityReference("systemuser", fromID); //gets the look up

		sendEmail["subject"] = emailSubject;
		sendEmail["from"] = new Entity[] { fromReciepent }; // this works
		sendEmail["description"] = fullhtml;
		sendEmail["bcc"] = "test@yahoo.com ";  // This does not work,
		sendEmail["to"] = new Entity[] { fromReciepent }; //this works

Guid emailID = service.Create(sendEmail); SendEmailRequest reqSendEmail = new SendEmailRequest(); reqSendEmail.EmailId = emailID; reqSendEmail.IssueSend = true; reqSendEmail.TrackingToken = ""; service.Execute(reqSendEmail);


The code works but am more concerned about this line that does not work because it is the most important

sendEmail["bcc"] = "test@yahoo.com ";  

I have changed the settings on CRM to allow unresolved recipients

emaill222.PNG

and have tested it from the front end, so why does it not work with the code.

test-221222.PNG 

*This post is locked for comments

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: Custom Workflow activity/Plugin to send Email to a recipient not in CRM

    Perfect thanks

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Custom Workflow activity/Plugin to send Email to a recipient not in CRM

    Try to use following:

    EntityCollection colAP = new EntityCollection();

    foreach (var item in userResult.Entities)

    {

    Entity activityParty = new Entity("activityparty");

    activityParty["addressused"] = item.Attributes["internalemailaddress"];

    colAP.Entities.Add(activityParty);

    }

    email["bcc"] = colAP;

  • lawix10 Profile Picture
    lawix10 330 on at
    RE: Custom Workflow activity/Plugin to send Email to a recipient not in CRM

    Thanks this worked perfectly, but created another error which is invalid email.

    Actually the emails exists on the , so may be it is why I get an invalid email error.

    so its a batch job to send email to a lot of users hence the bcc

    so the code below shows it

    string usersxml =
    @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
    <entity name='systemuser'>
    <attribute name='fullname' />
    <attribute name='systemuserid' />
    <attribute name='internalemailaddress' />
    <order attribute='fullname' descending='false' />
    <filter type='and'>
    <condition attribute='isdisabled' operator='eq' value='0' />
    <condition attribute='internalemailaddress' operator='not-null' />
    </filter>
    </entity>
    </fetch>";
    
    EntityCollection userResult = service.RetrieveMultiple(new FetchExpression(usersxml));
    
    string emailList = "";
    
    foreach (var item in userResult.Entities)
    {
    emailList += item.Attributes["internalemailaddress"]+";";
    }
    		


    So the email list will be user1@email.com;user2@email.com;user3@email.com;

    and so on..so when i put this on the bcc it throws an error...saying more than one match was found...

    is there a better way I can populate the bcc with lots of users on the system like the fectxml..

    else you already answered this question .

    Regard

  • Verified answer
    a33ik Profile Picture
    a33ik 84,323 Most Valuable Professional on at
    RE: Custom Workflow activity/Plugin to send Email to a recipient not in CRM

    Hello,

    Check following - paul-way.com/sending-unresolved-emails

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans