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)

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

I have the same question (0)
  • Kokulan Profile Picture
    18,054 on at

    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

  • Suggested answer
    Community Member Profile Picture
    on at

    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

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