proper way to send email from plugin? RRS feed

  • Question

  • Hello - Is this the proper way to send an email from a plugin?:

                var message = "test";
                var emailId = service.Create(new Email
                    To = new List<ActivityParty>
                        new ActivityParty
                            PartyId = new EntityReference(Contact.EntityLogicalName, contactId)
                    Subject = message,
                    Description = message,
                    RegardingObjectId = new EntityReference(Incident.EntityLogicalName, caseId)

    Should this code alone be enough to send an email from a plugin or is a different technique or more code needed?
    Wednesday, July 17, 2013 10:22 PM

All replies

  • You need to call a SendEmailRequest after you created the email record:

    SendEmailRequest sendEmailreq = new SendEmailRequest {
       EmailId = _emailId,
       TrackingToken = "",
       IssueSend = true
    SendEmailResponse sendEmailresp = (SendEmailResponse)_serviceProxy.Execute(sendEmailreq);


    My blog: www.crmanswers.net

    Wednesday, July 17, 2013 10:34 PM
  • Unfortunately, service.Execute() is returning an exception: "an unknown error occurred"

    Is this a common error (with known solution(s)) for vets working with SendEmailRequest?

    Thursday, July 18, 2013 1:39 AM
  • Is your deployment on premise? If so, check the Event Viewer on the CRM server for more information of the error. Once you do that, please post the error details on this thread.



    Friday, July 19, 2013 11:25 AM