Thursday, April 12, 2012

Dynamics CRM 2011 : C# Code for Sending Email to Unresolved Recipients

In Dynamics CRM 2011 we can send email to unresolved receipts (email address not resolved as CRM record email address i.e. Contact, Account email address etc.) either by manually typing the receipt address into the To field or can add the recipient via C# code as well. You can use the code below to send email to unresolved recipient.

Dynamics CRM 2011 will only allow email send to unresolved reciepents if “Allow messages with unresolved e-mail reciepents to be sent” option in System Settings will be enabed (Settings->Administration-System Settings->E-mail).
 [C# Code]

private void SendEmailToUnresolvedRecent(IOrganizationService prmCrmService, string 
             prmToRecipientEmailAddress, Guid prmSenderUserId, string prmSubject, string prmMessageBody)

            // Email record id
            Guid wod_EmailId = Guid.Empty;

            // Creating Email 'to' recipient activity party entity object
            Entity wod_EmailToReciepent = new Entity("activityparty");

            // Creating Email 'from' recipient activity party entity object
            Entity wod_EmailFromReciepent = new Entity("activityparty");

            // Assigning receiver email address to activity party addressused attribute
            //wod_EmailToReciepent["participationtypemask"] = new OptionSetValue(0);
            wod_EmailToReciepent["addressused"] = prmToRecipientEmailAddress;

            // Setting from user account
            wod_EmailFromReciepent["partyid"] = new EntityReference("systemuser", prmSenderUserId);

            // Creating Email entity object
            Entity wod_EmailEntity = new Entity("email");

            // Setting email entity 'to' attribute value
            wod_EmailEntity["to"] = new Entity[] { wod_EmailToReciepent };

            // Setting email entity 'from' attribute value
            wod_EmailEntity["from"] = new Entity[] { wod_EmailFromReciepent };

            // Setting email subject and description
            wod_EmailEntity["subject"] = prmSubject;

            wod_EmailEntity["description"] = prmMessageBody;

            // Creating email record
            wod_EmailId = prmCrmService.Create(wod_EmailEntity);

            // Creating SendEmailRequest object for sending email
            SendEmailRequest wod_SendEmailRequest = new SendEmailRequest();

            // Creating Email tracking token request object
            GetTrackingTokenEmailRequest wod_GetTrackingTokenEmailRequest = new GetTrackingTokenEmailRequest();

            // Creating Email tracking token response object to get tracking token value
            GetTrackingTokenEmailResponse wod_GetTrackingTokenEmailResponse = null;

            // Setting email record if for sending email
            wod_SendEmailRequest.EmailId = wod_EmailId;

            wod_SendEmailRequest.IssueSend = true;

            // Getting tracking token value
            wod_GetTrackingTokenEmailResponse = (GetTrackingTokenEmailResponse)
                                                 prmCrmService.Execute (wod_GetTrackingTokenEmailRequest);

            // Setting tracking token value
            wod_SendEmailRequest.TrackingToken = wod_GetTrackingTokenEmailResponse.TrackingToken;

            // Sending email



  1. thank you! was really helpful

  2. Thank you for this. I was unaware that from and to fields were activityparties, so I tried to give it an EntityReference with little results. Changed it to activityparties and it worked.

  3. For your information,
    i tried to put HTML content (instead of text) in the wod_EmailEntity["description"] and it works!

  4. Do you know if there is a way to avoid sending the trackingtoken ?

  5. Very well, the publish is actually the greatest on this deserving topic. I agree with your conclusions and will eagerly look forward to your incoming updates. Just saying thanks will not just be adequate, for the fantastic clarity in your writing. I will at once grab your rss feed to stay informed of any updates.

  6. Admiring the time and effort you put into your website and detailed information you provide. It’s awesome to come across a blog every once in a while that isn’t the same out of date rehashed material. Fantastic read! I’ve bookmarked your site and I’m including your RSS feeds to my Google account.

  7. La Robinet infrarouge proposent les designers actuels associés aux dernières innovations qui raviront les amateurs de des meilleurs prix sur notre large gamme de robinetterie dédiée à la cuisine. Mitigeurs évier tous robinet pour un équipement de qualité.Des équipements de qualité pour votre maison, et vous pouvez faire la cuisine qualité fiable robinet, vraiment dans votre chambre? Vous cherchez un robinet pour votre service de cuisine, nous avons ce qu'il vous faut! conçu pour fournir toutes sortes de Accessoires salle de bain, nous pouvons concevoir une variété de styles disponibles ici. Mitigeurs de cuisine Robinetsale : Vous trouverez ici le Mitigeur baignoire Mitigeur baignoire . Peu importe qui ouvre le robinet : ici coulent la qualité, le savoir-faire et le design.

  8. As a general rule, you should remember low pressure Taps Sale will work well with a high pressure water system; however, Basin Taps is not the same vice versa. In addition to seeking Bathroom Sink Taps that look good and offer great performance, Bathtub Taps should endeavor to get ones that are reasonably priced. By taking the time to compare the various options available you should be able to get fantastic Automatic Taps for your bath and basin that you will love for many years to come.

  9. Pour acheter votre robinet de lavabo pas cher, pour bénéficier du meilleur prix pour l'achat de votre robinet de lavabo.

  10. Exquisite petal pink morganite center stones are in full bloom in these stunning Morganite Rings . Sought after for their exceptional clarity and captivating blush tones, these gems are accentuated perfectly by delicate settings which allow for maximum light to enter the stone.

  11. Thanks for taking the time to discuss that, I feel strongly about this and so really like getting to know more on this kind of field. Do you mind updating your blog post with additional insight? It should be really useful for all of us.
    Bathroom Sink Taps

  12. صباغ الكويت افضل خدمة يحتاجها اهل الكويت فى الوقت الحالي حيث انه من النادر ان تجد صباغ بالكويت محترف ولكن اليوم فى موقع صباغ الكويت سوف تجد افضل صباغين وافضل ديكورات الكويت على احدث صيحه لعام 2021 مثل ورق جدران مودرن بالكويت  ويوجد لدينا تركيب باركية خشب بالكويت ومع ارتفاع الاسعار يمكنك ايضا تركيب بديل الرخام بالكويت وهناك موديلات جديده مثلا استيل الكويت  ناتي الى افضل صباغين بالكويت هنالك جنسيات مختلفة مثل صباغ مصري و صباغ باكستاني وايضا هنالك صباغ هندي جميع الصباغين على اعلى مستوى وبالاخص صباغ عراقي  ونقوم بتقديم الخدمات فى جميع مناطق الكويت مثل صباغ الجهراء  و صباغ مبارك الكبير  و صباغ حولي  و صباغ الفروانية بالاضافة الى صباغ العاصمة  و صباغ الاحمدي  جميع تلك الخدمات نقدمها بالاضافة الى صباغ وايضا صباغ بالكويت بالاضافة الى ارخص صباغ و اشطر صباغ و افضل صباغ ولدينا معلم صباغ يوجد لدينا افضل صباغ بالكويت