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)

Send Email Using Plugin

(0) ShareShare
ReportReport
Posted on by

Hello,


I am writing an plugin to send an email to a user.  Does anyone know how I could do this?  I have seen articles referencing ActivityParty, but I was not able to add the correct reference to use this class.

Any ideas?


Thanks,


Devin

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Karth Profile Picture
    on at

    There's sample code available within CRM SDK. You can reference the below link

    msdn.microsoft.com/.../hh210217.aspx

  • Cornel Croitoriu Profile Picture
    50 on at

    You can use the SendEmailRequest class. The partyId and type are mandatory.

  • Community Member Profile Picture
    on at

    Hello,

    I have implemented the code that was found in the SDK to send an email.  However I am getting an error upon debugging the code.

    "the specified sender type is not supported"

    I am passing a guid of a systemuser in CRM.

  • Aileen Gusni Profile Picture
    44,524 on at

    Devin,

    Can you copy paste your code here?

    It seems you copy paste a systemuser guid but use entity type other than allowed entities (user and queue)

  • Community Member Profile Picture
    on at

    Call to method:

    sendEmail(new Guid("7891B00E-ED80-E211-B2EA-02BFAC1A6434"), owner.Key, "systemuser", "Test Email", "Test Description", owner.Value);

    Method:

    private void sendEmail(Guid From, Guid To, string ToEntitySchemaName, string Subject, string Description, List<string> urls)

       {

           var description = new StringBuilder();

           description.AppendLine("Hello,");

           description.AppendLine("Text");

           description.AppendLine("<ul>");

           foreach (var address in urls) {

               description.AppendFormat("<li>{0}</li>", string.Format(HyperLinkFormat, address, "Link to things"));

           }

           description.AppendLine("</ul>");

           try

           {

               // Create 'From' activity party for the email

               ActivityParty fromParty = new ActivityParty

               {

                   PartyId = new EntityReference(SystemUser.EntityLogicalName, From)

               };

               // Create 'To' activity party for the email

               ActivityParty toParty = new ActivityParty

               {

                   PartyId = new EntityReference(ToEntitySchemaName, To)

               };

               // Create an e-mail message

               Email email = new Email

               {

                   To = new ActivityParty[] { toParty },

                   From = new ActivityParty[] { fromParty },

                   Subject = Subject,

                   Description = description.ToString(),

                   DirectionCode = true

               };

               Guid _emailId = _service.Create(email);

               SendEmailRequest sendEmailreq = new SendEmailRequest

               {

                   EmailId = _emailId,

                   TrackingToken = "",

                   IssueSend = true

               };

               SendEmailResponse sendEmailresp = (SendEmailResponse)_service.Execute(sendEmailreq);

               if (sendEmailresp != null)

               {

                   //Console.WriteLine("Email record created successfully");

                   //Console.ReadKey();

               }

           }

           catch (Exception ex)

           {

               //Console.Write("Errorex.Message);

               //Console.ReadKey();

               throw new InvalidPluginExecutionException(ex.Message);

           }

       }

  • Verified answer
    Community Member Profile Picture
    on at

    ANSWER:

    I was able to get the email to send.  One has go into the User profile in CRM, and click on "APPROVE EMAIL"

     

    This needs to be part of the documentation.  It should be more obvious that the email mailbox needs to be approved before emails can be sent via code.  Workflows send emails fine, but anything externally will not send unless you have approved the email address!

     

     

  • ShaikhAtif Profile Picture
    201 on at

    Aileen,

    i having error on this line :

    SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail); //error line

    reference :

    SendEmailRequest reqSendEmail = new SendEmailRequest();

                                   reqSendEmail.EmailId = _emailId;//ID of created mail

                                   reqSendEmail.TrackingToken = "";

                                   reqSendEmail.IssueSend = true;

    SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail);

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