1

I'm writing plugin C#, to send an email to the users who are under SystemCustomizer role notifying that Contact is creating or Updating.

How to send an email to multiple users (Bulkmailing/ forEach loop for creating mail request to every user)?

James Z
  • 12,209
  • 10
  • 24
  • 44
NaveenGNK
  • 93
  • 3
  • 12
  • 3
    What have you tried, blocked with some issue? – Arun Vinoth-Precog Tech - MVP Mar 10 '18 at 19:47
  • thank you @Arun.. I am trying to send a mail to multiple users everytime when the contact record is being updated or created. We know we can do from plugin. But the thing is I want to send at a time like bulksending.. can we do that..? – NaveenGNK Mar 19 '18 at 08:38
  • This is unclear. 1. Do you want to send for each contact create/update to all Sys customizers? 2. Or contact create/update summary everyday to SCs? 3. Do you want single email & all of them on To/Cc or individual email to each SC? – Arun Vinoth-Precog Tech - MVP Mar 20 '18 at 21:52
  • 1
    I'm not the guy that downvoted you, but here's why you were downvoted. Stack Overflow is a place for resolving particular, specific issues with software. You're expected to lay out what your problem is, including what you've tried and what error message your'e getting. It is not a place for "I don't know anything about this software, can someone give me teh codes?" – Michael Blackburn Apr 11 '18 at 21:29

1 Answers1

2

Use a query to find each system user entity with the system customiser role.

Then for each user send an email. 1; create the email, 2; send the email.

// Create an e-mail message.
Email email = new Email
{
    To = new ActivityParty[] { toParty },
    From = new ActivityParty[] { fromParty },
    Subject = "SDK Sample e-mail",
    Description = "SDK Sample for SendEmail Message.",
    DirectionCode = true
};
_emailId = _serviceProxy.Create(email);

// Use the SendEmail message to send an e-mail message.
SendEmailRequest sendEmailreq = new SendEmailRequest
{
    EmailId = _emailId,
    TrackingToken = "",
    IssueSend = true
};

SendEmailResponse sendEmailresp = (SendEmailResponse)_serviceProxy.Execute(sendEmailreq);
James Wood
  • 17,286
  • 4
  • 46
  • 89
  • what if you're emailing many Users at once... is there a better "bulk" way that CRM supports? Other than looping and creating and sending one at a time... – Don Cheadle Aug 10 '21 at 21:45
  • @DonCheadle marketing features, or make a workflow and run the workflow in bulk – James Wood Aug 11 '21 at 10:19