locked
Unable to send emails to records in Dynamics CRM 2015 RRS feed

  • Question

  • Hi,

    To give a brief overview of the environments attempted on:

    CRM 2015 : Online and On Premise

    Now, the problem. So, I'm trying to send an email to records like (account, contacts, etc.) using the Email Template in Dynamics CRM 2015.

    When I use the records created by the Sample Data in Dynamics CRM, the emails get created just fine. However, when I create a custom record (my own record) and attempt to send the email it keeps saying that either the activityparty email doesn't exist or has not allowed emails. I have checked multiple times, they are all there and also my sender (which happens to be the admin account) also has an email.

    Not sure what is causing this but I have tried almost every setting, but unable to figure out what might be going wrong. What's more interesting is whenever I try to create an email manually, the recipient shows up as red and also complains with the same message.

    Also, here's the code although I don't think there's something to do with the code since it's complaining when I create any email manually as well.

    private void SendEmail(IOrganizationService orgService, string templateEntityName, string toEntityName, Guid toPartyId, Guid fromPartyId, Guid emailTemplateId)
            {
                Entity Fromparty = new Entity("activityparty");
                Entity Toparty = new Entity("activityparty");
    
                //set partyid
                Toparty["partyid"] = new EntityReference(toEntityName, toPartyId);
                Fromparty["partyid"] = new EntityReference("systemuser", fromPartyId);
    
                //create email  and set attributes
                Entity emailCreate = new Entity("email");
                emailCreate["from"] = new Entity[] { Fromparty };
                emailCreate["to"] = new Entity[] { Toparty };
    
                // Create the request
                SendEmailFromTemplateRequest emailUsingTemplateReq = new SendEmailFromTemplateRequest
                {
                    Target = emailCreate,
    
                    // Use a built-in Email Template of type "contact".
                    TemplateId = emailTemplateId,
    
                    // The regarding Id is required, and must be of the same type as the Email Template.
                    RegardingId = toPartyId,
                    RegardingType = templateEntityName
                };
    
                SendEmailFromTemplateResponse emailUsingTemplateResp = (SendEmailFromTemplateResponse)orgService.Execute(emailUsingTemplateReq);
    
                // Verify that the e-mail has been created
                Guid _emailId = emailUsingTemplateResp.Id;
            }

    This is how I invoke it

     obj.SendEmail(_orgService, "account", "account", new Guid("65816768-56DB-E411-80F0-C4346BAD367C"), new Guid(mailFrom), new Guid("B6C38BB9-2423-471D-8B38-E3B99ED80E7A"));

    Any idea what might be going wrong?

    Thanks!


    Admin QuikView Solution for CRM 2013


    Sunday, April 5, 2015 7:30 AM

All replies

  • Hello,

    As for me - answer is obvious and I will try to help to answer by yourself. Recheck 2 parts of your question and try to find contradiction:

    // Use a built-in Email Template of type "contact".
    TemplateId = emailTemplateId,

    and

    obj.SendEmail(_orgService, "account", "account", new Guid("65816768-56DB-E411-80F0-C4346BAD367C"), new Guid(mailFrom), new Guid("B6C38BB9-2423-471D-8B38-E3B99ED80E7A"));


    Dynamics CRM MVP
    My blog

    Sunday, April 5, 2015 8:57 AM
    Moderator
  • Hi Andrii,

    The comments says "contact" but it's just supposed to be a typo in there when I initially wrote the code. In actual, the Template Id belongs to that of "account". So, there is no contradiction in actual. If you see my method, I'm passing the Template Id for the respective entity for which I need to send emails.

    Also, why does Dynamics CRM prevent me from creating emails manually (if you see my second screenshot).

    Am I missing out any settings or anything?

    Thanks!


    Admin QuikView Solution for CRM 2013

    Monday, April 6, 2015 5:24 PM
  • Hello,

    Can you please confirm that both account and your systemuser records have email field populated? First screenshot shows that primary contact record contains email.


    Dynamics CRM MVP
    My blog

    Monday, April 6, 2015 5:57 PM
    Moderator
  • Hi Andrii,

    The account doesn't have any separate field for an email right? It's fetched from the associated Contact, I guess (first screenshot)?

    As far as the systemuser goes, yes it does have an email specified. Also, if there was something with the systemuser it would prevent me from sending emails to any record - but it allows me to send email to the records created by Dynamics CRM Sample Data population.

    Is this something only I'm facing? Has anyone else faced this?

    Thanks!


    Admin QuikView Solution for CRM 2013

    Monday, April 6, 2015 6:52 PM
  • Hello,

    Account does have separated field for email (emailaddress1 field if I'm not wrong) and it is used to send emails to accounts (and not email from contact shown on a first screenshot). In case mentioned field is not populated - you have an answer why both code and GUI email send doesn't work.


    Dynamics CRM MVP
    My blog


    Monday, April 6, 2015 6:58 PM
    Moderator