Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

want to send email to group of users who are all outside of CRM vai plugin

(0) ShareShare
ReportReport
Posted on by

hi ,

can you guys help me to find out the solution for sending email for users who are all not from MS CRM.

I have tried the below code but it is not working.or else vai workflow also but without creating account or contacts etc.

string[] emailname = { "srv@gmail.com;", "abc@gmail.com;" };

EntityCollection colAP = new EntityCollection();
Entity activityParty = new Entity("activityparty");
activityParty["addressused"] = emailname;
colAP.Entities.Add(activityParty);

Entity template = GetGlobalTemplate("Auto mail configuration for scheduling Risk Review", service);
Entity email = new Entity("email");
Entity from = new Entity("activityparty");
from["partyid"] = new EntityReference("systemuser", ContextObject.context.UserId);
tracingService.Trace("from:" + ContextObject.context.UserId.ToString());
Entity[] SendFrom = { from };
email["from"] = SendFrom;
email["to"] = colAP;
Guid EmailId = service.Create(email);
SendEmailFromTemplateRequest emailtempreq = new SendEmailFromTemplateRequest
{
Target = email,
TemplateId = template.Id,
RegardingId = targetEntity.Id,
RegardingType = "opportunity"
};

SendEmailFromTemplateResponse emailtempresp = (SendEmailFromTemplateResponse)service.Execute(emailtempreq);

awaiting for you reply,

Muthukumaran M.

*This post is locked for comments

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: want to send email to group of users who are all outside of CRM vai plugin

    hi  Kokulan Eswaranathan (கோகுலன் ஈஸ்வரநாதன்),

    we need to add some more think to your code to work i have attached my working code.

    Thank you so much kokul.

    Entity template = GetGlobalTemplate("Auto mail configuration for scheduling Risk Review", service);

               Entity email = new Entity("email");

               Entity from = new Entity("activityparty");

               from["partyid"] = new EntityReference("systemuser", ContextObject.context.UserId);

               tracingService.Trace("from:" + ContextObject.context.UserId.ToString());

               Entity[] SendFrom = { from };

               email["from"] = SendFrom;

               EntityCollection colAP = new EntityCollection();

    string[] emailname = {"srv@gmail.com", "abc@gmail.com" };

    foreach (var emailAddress in emailname)

                   {

                       if (!string.IsNullOrWhiteSpace(emailAddress))

                       {

                           Entity toParty = new Entity("activityparty");

                           toParty.Attributes.Add("addressused", emailAddress);

                           colAP.Entities.Add(toParty); ;

                       }

                   }

    email["to"] = colAP;

               Guid EmailId = service.Create(email);

               // Guid EmailId = service.Create(email);

               SendEmailFromTemplateRequest emailtempreq = new SendEmailFromTemplateRequest

               {

                   Target = email,

                   TemplateId = template.Id,

                   RegardingId = targetEntity.Id,

                   RegardingType = "opportunity"

               };

               SendEmailFromTemplateResponse emailtempresp = (SendEmailFromTemplateResponse)service.Execute(emailtempreq);

    Regards,

    Muthukumaran M,

    L&T Infotech,

    Karaikal,

    Chennai.

    India

  • Kokulan Profile Picture
    18,054 on at
    RE: want to send email to group of users who are all outside of CRM vai plugin

    Hi

    Could you try the following code and see if this works for you?

    string[] emailname = { "srv@gmail.com;", "abc@gmail.com;" };
    List<Entity> colAP = new List<Entity>();
    foreach (var emailAddress in emailname)
    {
    if (!string.IsNullOrWhiteSpace(emailAddress))
    {
    Entity toParty = new Entity("activityparty");
    toParty["addressused"] = emailAddress;
    colAP.Add(toParty);
    }
    }

    Entity template = GetGlobalTemplate("Auto mail configuration for scheduling Risk Review", service);

    Entity from = new Entity("activityparty");
    from["partyid"] = new EntityReference("systemuser", ContextObject.context.UserId);
    tracingService.Trace("from:" + ContextObject.context.UserId.ToString());
    Entity[] SendFrom = { from };


    Entity email = new Entity("email");
    email["from"] = SendFrom;
    email["to"] = colAP.ToArray();

    SendEmailFromTemplateRequest emailtempreq = new SendEmailFromTemplateRequest
    {
    Target = email,
    TemplateId = template.Id,
    RegardingId = targetEntity.Id,
    RegardingType = "opportunity"
    };

    Allowing CRM to send emails to unresolved email addresses, please see below

    ScreenClip-_5B00_768_5D00_.png

    And if your users emails are not approved and if you want emails to be sent from those users, you will have to untick the following settings as well.

    ScreenClip-_5B00_768_5D00_.png

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans