web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Plugin: Email Multiple People from one field

(0) ShareShare
ReportReport
Posted on by 180

I have a plugin that sends an email where we routinely need to add/remove people to the email list. Some of these people are CRM users, some are not.

I have a configuration entity that I want to reference a field that contains a string of all of the email addresses that I want to email. Here I can add and remove emails easily without having to promote a new piece of code or have to create multiple fields for each individual email.

I found the code below where you can enter in an email address to email someone that is not a user or contact in CRM. However, if I enter in two email addresses like in the commented code below, it only emails the last email address. 

Can you help me email more than one person from one field? If not, do you have a better suggestion to handle this? Thank you in advance.

// Create a new unresolved activity party
Entity party2 = new Entity("activityparty");
party2["addressused"] = "unresolved@email.com";

//Does Not Work, only emails last email address
//party2{"addressedused"} = "unresolved@email.com;testperson@email.com";

// Create a new EntityCollection and add the 2 parties
EntityCollection to = new EntityCollection();
to.Entities.Add(party2);

*This post is locked for comments

I have the same question (0)
  • Chadi Tannous Profile Picture
    1,039 on at

    Try this

    EntityCollection EntityCollection= new EntityCollection();

      Entity activityParty = new Entity("activityparty");

      activityParty["addressused"] = emailAddress;

      EncityCollection.Entities.Add(activityParty);

    //add as many EntityCollection entities as you want

    email["to"] = EntityCollection;

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Mike,

    Eash activity party represent a single email. Change you code as below and try-

                   // Create a new unresolved activity party 1

                   Entity party1 = new Entity("activityparty");

                   party1["addressused"] = "unresolved1@email.com";

                   Entity party2 = new Entity("activityparty");

                   party2["addressused"] = "unresolved2@email.com";

                   //... add as many parties as you want same as party1, party2

                   // Create entity collection and add all the parties

                   EntityCollection to = new EntityCollection();

                   to.Entities.Add(party1);

                   to.Entities.Add(party2);

                   // add additonal parties here as well say party3, 4 ...

    Hope this helps

    Please close the thread once you get the answer for your question by marking the suggestions as helpful.

  • Mike Karls Profile Picture
    180 on at

    Hello,

    I appreciate you taking the time to answer my question, but this does not solve my problem. I am trying to have all the email addresses in one field, not one field per one email address. Several people need to be on the email and I do not want to have to create several fields. I would have to at least create 10 email fields.

  • RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Mike,

    From your description, I understand that you have extracted the different email addressed from your configuration entity and now want to send an email (single email) to all the email addresses retrieved from the config entity?

    The above code should add multiple email address on too field of the same email record.

    Isn't this what you are looking for?

  • Mike Karls Profile Picture
    180 on at

    I have 1 field in CRM that I want to store all of the email addresses.

    For example, field new_email contains "testperson1@email.com; testperson2@email.com; testperson3@email.com; testperson4@email.com; testperson5@email.com"

    I want this 1 field that contains multiple email addresses to send one email to all of the email addresses that are on the 1 field.

  • Verified answer
    Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    Mike,

    What I would do in this case is create an array of the email addresses from your file, and add each one to the Entity Collection.

    string emailAddresses = "testperson1@email.com;testperson2@email.com;testperson3@email.com;testperson4@email.com;testperson5@email.com";

    string[] splitEmails = emailAddress.split(';');

    EntityCollection activityParties = new EntityCollection();

    foreach (string emailAddress in splitEmails)

    {

      Entity party = new Entity("activityparty");

      party["addressused"] = emailAddress;

       EntityCollection.Entities.Add(party);

    }

    Hope this helps.

  • ashlega Profile Picture
    34,477 on at

    Hi Mike,

     maybe there is a bit of confusion above..

     When you do this:

    email["to"] = EntityCollection;

     That email will be sent to all activity parties in the EntityCollection (one email.. with multiple recipients).

     But you do have to create an entity collection, so, even if you store all emails in one field, you still have to parse them as Aric suggested above.

  • Mike Karls Profile Picture
    180 on at

    Yes! This is it! Thank you very much!!!!

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans