Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Send Email to list of emails.

Posted on by Microsoft Employee

I am creating a C# plugin, and I am having some issues sending an email to a list of emails.

From a workflow activity, I returned a list of emails in a string, but it looks like the OOB Send Email activity requires a lookup for the To/CC/BCC fields.

Is there a way I can accomplish this?

I have tried looking at this sample from Microsoft, but I cannot for the life of me find where the Email class is defined: https://msdn.microsoft.com/en-us/library/hh210217.aspx

Thanks,

*This post is locked for comments

  • prt33k Profile Picture
    prt33k 6,907 on at
    RE: Send Email to list of emails.

    ah! late reply :)

  • Suggested answer
    prt33k Profile Picture
    prt33k 6,907 on at
    RE: Send Email to list of emails.
    public void SendEmailToUnresolvedRecipient(IOrganizationService crmService,
    string recipientEmailAddress,
    Guid senderUserId,
    string prmSubject,
    string prmMessageBody)
            {
    
                // Creating Email 'to' recipient activity party entity object
                Entity emailToReciepent = new Entity("activityparty");
    
                // Creating Email 'from' recipient activity party entity object
                Entity emailFromReciepent = new Entity("activityparty");
    
                // Assigning receiver email address to activity party addressused attribute
                emailToReciepent["addressused"] = recipientEmailAddress;
    
                // Setting from user account
                emailFromReciepent["partyid"] = new EntityReference("systemuser", senderUserId);
    
                // Creating Email entity object
                Entity emailEntity = new Entity("email");
    
                // Setting email entity 'to' attribute value
                emailEntity["to"] = new Entity[] { emailToReciepent };
    
                // Setting email entity 'from' attribute value
                emailEntity["from"] = new Entity[] { emailFromReciepent };
    
                // Setting email subject and description
                emailEntity["subject"] = prmSubject;
    
                emailEntity["description"] = prmMessageBody;
    
                // Creating email record
                Guid emailId = crmService.Create(emailEntity);
    
                // Creating SendEmailRequest object for sending email
                SendEmailRequest sendEmailreq = new SendEmailRequest
                {
                    EmailId = emailId,
                    TrackingToken = "",
                    IssueSend = true
                };
    
                SendEmailResponse sendEmailresp = (SendEmailResponse)crmService.Execute(sendEmailreq);
    
            }

    This should work..

    Prateek

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Send Email to list of emails.

    Thank you so much for your help!

    The problem was that the to/from/cc/bcc list required an Entity of type activityparty. The late-bound example made this clear to me.

  • Verified answer
    ashlega Profile Picture
    ashlega 34,475 on at
    RE: Send Email to list of emails.

    Hi,

     you need to generate those early-bound classes first:

    msdn.microsoft.com/.../gg327844.aspx

     If you wanted to use late-bound, there is an example here:

    mubashersharif.blogspot.ca/.../send-email-using-late-binding-crm-2011.html

      As for the lookup vs plain text address, you can configure what's allowed if you go to Settings->Administration->System Settings->Email->"Allow messages with unresolved email recipients to be sent"

     Once you've configured that option, you can use this as an example:

    paul-way.com/sending-unresolved-emails

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans