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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to send email to both email ids of a contact in single email though Code

(0) ShareShare
ReportReport
Posted on by 651

Hi,

We have contact entity with two email fields available per contact. How to send  single email by appending multiple email address at time. Using below code was able to get only one email id field.

private void SendEmail(Guid accountToGuid)

{

Entity toParty = new Entity("activityparty");

toParty["partyid"] = new EntityReference("contact", accountToGuid);

 

}

*This post is locked for comments

I have the same question (0)
  • Integration Profile Picture
    651 on at
    RE: How to send email to both email ids of a contact in single email though Code

    Thanks guys it worked..

    if (item.Attributes["emailaddress1"]!=null)

                               {

                                   toParty["addressused"] = item.Attributes["emailaddress1"].ToString();

                                   toParty["partyid"] = new EntityReference("contact", receiverUID);

                                   toPartyArray.Add(toParty);

                                   collToParty.Entities.Add(toParty);

                                   EmailAddress = string.Empty;

                               }

                               Entity toParty1 = new Entity("activityparty");

                               if (item.Attributes["emailaddress2"] != null)

                               {                                

                                   toParty1["addressused"] = item.Attributes["emailaddress2"].ToString();

                                   toParty1["partyid"] = new EntityReference("contact", receiverUID);

                                   toPartyArray.Add(toParty1);

                                   collToParty.Entities.Add(toParty1);

                                   EmailAddress = string.Empty;

                               }

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: How to send email to both email ids of a contact in single email though Code

    Hi Krish,

    If you set the entity reference object for the Party then CRM will send teh email to the primary email. If you want multiple email, then you need to use the"addressused" field of the party. Refer below blog-

    paul-way.com/sending-unresolved-emails

    Hope this helps.

  • Verified answer
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: How to send email to both email ids of a contact in single email though Code

    Hi Krish,

    You need to create entitycollection object to pass multiple email address into 'To' party. Please do refer following code for reference:

    EntityCollection collToParty = new EntityCollection();

    Entity toParty = new Entity("activityparty");

    string EmailAddress = Contact.Attributes.Contains("emailaddress") ? (string)Contact.Attributes["emailaddress"] : string.Empty;

    if (EmailAddress != string.Empty)

    {

    toParty["addressused"] = EmailAddress;

    toParty["partyid"] = new EntityReference("systemuser", User.Id);

    toPartyArray.Add(toParty);

    }

    collToParty.Entities.Add(toParty);

    Entity Email = new Entity("email");

    Email.Attributes.Add("to", collToParty);

  • Suggested answer
    Temmy Wahyu Raharjo Profile Picture
    2,914 on at
    RE: How to send email to both email ids of a contact in single email though Code

    Hi,

    This is not possible to do because the design for this one is base on Activity Entity (it will take one attribute name emailaddress). For your requirement you need to create child entity (need to be activity). Then on your plugin that one, you need to retrieve and add all the child entity to the email to/cc/bcc.

    Hope this help.

  • Suggested answer
    Dynamics365 Rocker Profile Picture
    7,755 on at
    RE: How to send email to both email ids of a contact in single email though Code

    You can use one address in "To" and second one is in "CC". To achieve this functionality, You have to write a plug-in or workflow, below is link for your help:

    community.dynamics.com/.../sending-email-to-an-alternate-secondary-email-address

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans