Skip to main content

CRM to SendEmail

Send email functionality with CRM
     internal static Boolean SendEmail(string toAddress, Guid? fromPartyGuid, string subjectLine, string body, Guid? contactId,string templateName)  
     {  
       CrmService crmService = GetCrmService();  
       //[[FROM activity party for the email.  
       activityparty fromParty = new activityparty();  
       fromParty.partyid = new Lookup();  
       fromParty.partyid.type = EntityName.queue.ToString();  
       fromParty.partyid.Value = fromPartyGuid;   
       //]]       
       //[[TO activity party for email  
       activityparty toParty = new activityparty();  
       toParty.partyid = new Lookup();  
       toParty.partyid.type = EntityName.contact.ToString();  
       toParty.partyid.Value = (contactId.HasValue) ? contactId.Value : new Guid("");  
       //]]  
       //[[Create a new email and set its properties  
       email emailInstance = new email();  
       //set email parameters  
       emailInstance.from = new activityparty[] { fromParty };  
       emailInstance.to = new activityparty[] { toParty };  
       emailInstance.subject = subjectLine;  
       emailInstance.description = body;  
       emailInstance.regardingobjectid = CreateLookup(contactId.ToString(), EntityName.contact);  
       emailInstance.trackingtoken = templateName;  
       //]]  
       //Create a GUID for the email  
       Guid emailId = crmService.Create(emailInstance);  
       //Create a SendEmailRequest  
       SendEmailRequest request = new SendEmailRequest();  
       request.EmailId = emailId;  
       request.IssueSend = true;  
       request.TrackingToken = "";  
       //Execute request  
       SendEmailResponse sendEmailresp = (SendEmailResponse)crmService.Execute(request);  
       return true;  
     }  
           public static Lookup CreateLookup(string guid, EntityName lookupType)  
     {  
       if (string.IsNullOrEmpty(guid)) return null;  
       Lookup lkup = new Lookup();  
       lkup.Value = new Guid(guid);  
       lkup.type = lookupType.ToString();  
       return lkup;  
     }  

Comments

Popular posts from this blog

Localization in Umbraco, Item Page field localization

Umbraco is one of the most deployed Web Content Management Systems on the Microsoft stack. It's in the top five most popular server applications and among the ten most popular open source tools in general. You can directly download and start using it from http://www.umbraco.com If you have not used the application yet, its always worth trying it once. I am sure you will love it. Well, for the first time users, Umbraco provide step by step instruction for initial set up, once you are done you can use some sample template or create a blank website. To know more on umbraco, Please refer below links http://our.umbraco.org/wiki/how-tos/a-complete-newbie's-guide-to-umbraco http://umbraco.com/help-and-support/video-tutorials/getting-started?freeVideos=1 http://our.umbraco.org/wiki/how-tos/getting-started-with-umbraco-what-is-next-after-you-install http://our.umbraco.org/wiki/install-and-setup ,  I have created a blank website, Now we will go step by step. Fi...

DD4TFormRouteHandler (posting a form as tridion page url)

ASP.NET routing enables us to use URLs that are not physical files, In DD4T we have the default page route definition. In which all page request redirct to Page controller and process the page. DD4TFormRouteHandler is a custom route handler responsible for mapping incoming browser requests to particular MVC controller actions, this works along with  DD4TFormHelper  (that generate the route information for the form) Posting a form in DD4T is not complicated, you can create the mvc form as a normal controller and action, then post it via AJAX. But, when we need to do post the form as normal page, It would need a tweak as the controller/action is not a page existed in tridion. This can be achieved by implementing a custom Mvc RoutHandler and reroute the posted form to the encrypted action and controller. It works as below daigram. So, how to do this. to render out the form we have BeginDD4TForm html helper as below that generate the form with encrypted route values....

pjax with MVC, and form post like pjax

Last weekend I was working on a interesting project, and came across an interesting JavaScript library called pjax. More information on pjax: https://github.com/defunkt/jquery-pjax/ http://pjax.heroku.com/ pjax loads HTML from your server into the current page without a full reload. It's ajax with real permalinks, page titles, and a working back button that fully degrades, It just enhances the browsing experience. I just loved the way we could use it with MVC; Below code sample explains how we could use the same with MVC. Clientside code would look as below: Since the Form post is not handled with pjax, we can do a work around as below. Updated _ViewStart.cshtml as below: @{ if (Request.Headers["X-PJAX"] != null || Request.Headers["AJAX-FORM"]!=null) { Layout = "~/Views/Shared/_PjaxLayout.cshtml"; } else { Layout = "~/Views/Shared/_Layout.cshtml"; } } _PjaxLayout.cshtml ...