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

Announcements

No record found.

News and Announcements icon
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

  • 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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
TNJ_CRM_Team Profile Picture

TNJ_CRM_Team 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans