Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Send Email using .NetCore Odata with queue as sender

(0) ShareShare
ReportReport
Posted on by 745

Hi All,

    i have been developing an integration with Dyanmics CRM  through webAPI in .NetCore 

   i have been doing all operations using ODATA queries so

   I need to send Email using shared Mailbox/queues using this ODATA services

  can anybody knows how to send it or with some sample Code

Thanks 

  • Suggested answer
    MMK Profile Picture
    MMK 745 on at
    RE: Send Email using .NetCore Odata with queue as sender

    Hi Bipin,

      Thanks your reply helped me out

       i was having issues setting from and To fields and calling the send action in .NetCore

      here is code for any body in >netCore

    public static async Task<dynamic> PostMethod(dynamic Obj, string apiname)

           {

               try

               {

                   var token = GetToken();

                   var httpClient = new HttpClient

                   {

                       BaseAddress = new Uri(resource +"api/data/v9.1/"),

                       Timeout = new TimeSpan(0, 2, 0)

                   };

                   httpClient.DefaultRequestHeaders.Add("OData-MaxVersion", "4.0");

                   httpClient.DefaultRequestHeaders.Add("OData-Version", "4.0");

                   httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                   httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

                   httpClient.DefaultRequestHeaders.Add("Prefer", "return=representation");

                   // Add this line for TLS complaience

                   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

                   try

                   {

                       //+ "?$select=" + parameter

                       HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, apiname)

                       {

                           Content = new StringContent(Obj.ToString(), Encoding.UTF8, "application/json")

                       };

                       var res = await httpClient.SendAsync(request);

                       if (res.IsSuccessStatusCode)

                       {

                           var jRetrieveResponse = JObject.Parse(res.Content.ReadAsStringAsync().Result);

                           dynamic coll  = JsonConvert.DeserializeObject(jRetrieveResponse.ToString());

                           return coll ;

                       }

                       else

                       {

                           throw new Exception();

                       }

                   }

                   catch (Exception ex)

                   {

                       throw ex;

                   }

               }

               catch (Exception ex)

               {

                   throw ex;

               }

           }

     public async Task SendEmail(string contactid,string QueueId, string emailContent)

           {

               try

               {

                   JObject data = JObject.Parse(@"  

                                       {

                                           'description': '" + emailContent + @"',  

                                           'regardingobjectid_contact@odata.bind':  '/contacts('" +contactid+ @"')',

                                           'subject': 'Test Email Creation',

                                           'email_activity_parties': [

                                               {

                                                   'partyid_queue@odata.bind': '/queues('" + QueueId + @"')',

                                                   'participationtypemask': 1  

                                               },

                                               {

                                                   'partyid_contact@odata.bind': '/contacts('" + contactid + @"')',

                                                   'participationtypemask': 2

                                               }

                                           ]

                                       }");

                   dynamic newEmailContact = await SV.PostMethod(data, "emails");

                   var activityid = newEmailContact.activityid;

                   string apiname = "emails("+Convert.ToString(activityid)+")/Microsoft.Dynamics.CRM.SendEmail";

                   JObject EmailContact = new JObject { };

                   EmailContact["IssueSend"] = true;

                   dynamic ress= await SV.PostMethod(EmailContact, apiname);

               }

               catch (Exception ex)

               {

               }

           }

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,961 Moderator on at
    RE: Send Email using .NetCore Odata with queue as sender

    Hi,

    You can create email entity record and then use SendEmail action to send that email.

    Now you will need to define your Send and Receipient in your email object.

    Please see below blog which will guide you on the object construct.

    vblogs.in/.../

    and if you are looking for sample web api code for c# then check below docs page-

    docs.microsoft.com/.../web-api-samples-csharp

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans