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)

How to create an email activity through C#.Net?

(0) ShareShare
ReportReport
Posted on by 155

Hi All,

I need one help!

I have the code below to create an email activity in CRM 2011 but i dont know how to send it immediately as it is created.

ClientCredentials Credentials = new ClientCredentials();
        Credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

        //This URL needs to be updated to match the servername and Organization for the environment.

        Uri OrganizationUri = new Uri("http://ftssqa/FastTrack/XRMServices/2011/Organization.svc");
        Uri HomeRealmUri = null;

        //OrganizationServiceProxy serviceProxy;       

        using (OrganizationServiceProxy serviceProxy = new OrganizationServiceProxy(OrganizationUri, HomeRealmUri, Credentials, null))
        {
            IOrganizationService service = (IOrganizationService)serviceProxy;

            //Instantiate the contact object and populate the attributes.
            Entity emailCreate = new Entity("email");
            emailCreate["subject"] = "test subject";
            emailCreate["description"] = " test description";

            Entity ap = new Entity();
            Entity ap2 = new Entity();

            //You can comment out the line for addressused and use the partid instead to use an entity reference for an activity party
            //I just wanted to show how you can specify an email address for an email as an activity party without an entity to go with it.
            ap = new Entity("activityparty");
            //ap["partyid"] = new EntityReference("systemuser", new Guid("CE08EE7F-4F36-E111-B6F6-0050569838D6"));
            ap["addressused"] = "dhaval.panchal@fasttrackteam.com";
            Entity[] aryTo = { ap };
            emailCreate["to"] = aryTo;

            ap2 = new Entity("activityparty");
            ap2["partyid"] = new EntityReference("systemuser", new Guid("5ACD43CE-4C09-E211-8627-E06995886FCB"));
            Entity[] aryFrom = { ap2 };
            emailCreate["from"] = aryFrom;

            // This is how you assign an a reguarding object
            emailCreate["regardingobjectid"] = new EntityReference("account", new Guid("4AFAE8DB-FB11-E211-8655-E06995886FCB"));
            
            Guid newContactId = service.Create(emailCreate);
            
            //This code will clear the textboxes after the contact is created.
        }

Any suggestion? Also i need to get all email activities send/receive times with subject from CRM.

Please share your idea and would be appreciated!

Thank You in Advance.

Dhaval Panchal

 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Gus Gonzalez Profile Picture
    27,113 on at

    I would probably have the code change a field in CRM that triggers a workflow to create the activities and send them out instead of creating the whole solution via code.

    For example, you add a two-options field in CRM called "Run Workflow", when the code runs it sets the field to Yes, the workflow runs and it does it's thing setting the field back to No in the process. Repeat this as needed.

    Does that make sense?

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