locked
CRM 2011 : Send email using template send successfully but reading wrong user parameters RRS feed

  • Question

  • Hi,

    am using a custom aspx page developed in C# to send email using template from lead entity..

    1. using the proxy authentication with logged in systemuserid
    2. email owner and from parameter taking the correct user - "systemuser"
    3. template is having user address, phone number, email parameters to display as signature - these parameters are reading on wrong systemuser

    below is the code in place ...

     Entity email = new Entity();
     email.LogicalName = "email";

     email["ownerid"] = new EntityReference("systemuser", new Guid(userId));

     EntityReference regardingObject = new EntityReference("lead", new Guid(LeadId));
     email.Attributes.Add("regardingobjectid", regardingObject);

     EntityReference from = new EntityReference("systemuser", new Guid(userId));
     //EntityReference to = new EntityReference("systemuser", new Guid(ToUserId));
     EntityReference to = new EntityReference("lead", new Guid(LeadId));

     Entity fromParty = new Entity("activityparty");
     fromParty.Attributes.Add("partyid", from);
     Entity toParty = new Entity("activityparty");
     toParty.Attributes.Add("partyid", to);

     EntityCollection collFromParty = new EntityCollection();
     collFromParty.EntityName = "systemuser";
     collFromParty.Entities.Add(fromParty);

     EntityCollection collToParty = new EntityCollection();
     collToParty.EntityName = "systemuser";
     collToParty.Entities.Add(toParty);

     email.Attributes.Add("from", collFromParty);
     email.Attributes.Add("to", collToParty);

     email.Attributes.Add("subject", "Welcome Email");
     email.Attributes.Add("description", "Welcome Email");

     SendEmailFromTemplateRequest emailUsingTemplateReq = new SendEmailFromTemplateRequest
     {
         Target = email,
         TemplateId = new Guid(mnuDropStatusCode.SelectedValue.ToString()),
         RegardingId = new Guid(LeadId),
         RegardingType = "lead"
     };

     SendEmailFromTemplateResponse emailUsingTemplateResp = (SendEmailFromTemplateResponse)_serviceProxy.Execute(emailUsingTemplateReq);


    Alby

    Wednesday, May 7, 2014 10:33 PM

Answers

  • I expect the problem is with how you impersonate the user, rather than your code.

    How are you setting the Credentials on _serviceProxy, what are your IIS and ASP.Net impersonation settings, and what authentication type does the CRM server use ?


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by A L B Y Thursday, May 22, 2014 10:12 PM
    Thursday, May 8, 2014 6:59 AM
    Moderator

All replies

  • I expect the problem is with how you impersonate the user, rather than your code.

    How are you setting the Credentials on _serviceProxy, what are your IIS and ASP.Net impersonation settings, and what authentication type does the CRM server use ?


    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    • Marked as answer by A L B Y Thursday, May 22, 2014 10:12 PM
    Thursday, May 8, 2014 6:59 AM
    Moderator
  • I was caching the user login ... fixed by removing caching ...

    thanks for guiding to correct track ...


    Alby

    Thursday, May 22, 2014 10:12 PM