Looking for PowerObjects? Don’t worry, you’re in the right place! We’ve been part of HCL for several years, and we’ve now taken the final step in our acquisition journey: moving our website to the HCL domain. Nothing else is changing – we are still fanatically focused on Microsoft Business Applications!

PowerObjects Blog 

for Microsoft Business Applications


Open an Email Activity in Outlook from Dynamics CRM

Post Author: Joe D365 |

There may be a scenario when working in Dynamics CRM where you want to open an email activity in Outlook, as Outlook provides a richer set of formatting and usability options. Yet, if the email record is created (perhaps automatically) within CRM, you'll want it to stay in CRM. In addition, you'll want an easy way to move it to Outlook and automatically populate the body, subject, and recipients, etc. with data from CRM email activity.

Good news! You can accomplish the this by creating a new JavaScript web resource in CRM which will grab each specific email field value, open a new Outlook email, and populate the fields in the Outlook email.

As a use case, you can add a custom ribbon button called "Send Email to Outlook" on the email activity form. The button will call a JavaScript function which would read the email fields from the current record and pass them along to the function below, which will then open a new Outlook email and populate the fields. You may, in addition, populate additional fields such as From, or BCC, or Priority or even add attachments.

function Email(To, Subject, Body) {
    try {
        var theApp = new ActiveXObject("Outlook.Application");
        var objNS = theApp.GetNameSpace('MAPI');

        // value 0 = MailItem
        var theMailItem = theApp.CreateItem(0)

        //Bind the variables with the email
        theMailItem.to = To;
        //"Subject";
        theMailItem.Subject = Subject;

 // "Body";
        theMailItem.Body = Body;

        //Show the mail before sending for review purpose
        theMailItem.display();

        //You can directly use the theMailItem.send() function
        //if you do not want to preview the message first.
    }
    catch (err) {
        alert(err);
    }
}

This solution provides an easy, quick, and efficient way to move the contents of a CRM email activity that is created in CRM to a more user-friendly environment in Outlook.

Note: To open email in Outlook, Outlook needs to be up and running.

Important: As this code utilizes the ActiveXObject, it will only work if using Internet Explorer.

Hope you find this useful. Happy CRM'ing!

Joe CRM
By Joe D365
Joe D365 is a Microsoft Dynamics 365 superhero who runs on pure Dynamics adrenaline. As the face of PowerObjects, Joe D365’s mission is to reveal innovative ways to use Dynamics 365 and bring the application to more businesses and organizations around the world.

14 comments on “Open an Email Activity in Outlook from Dynamics CRM”

  1. how to resolve formatting issue of email, it is displaying html in the outlook body. how we can convert it into proper formatted text.

    1. Hi Alex, Can we set email regarding field in the outlook when we open email activity in outlook using ribbon button?

  2. Hi Alex, Can we set email regarding field in the outlook when we open email activity in outlook using ribbon button??

  3. Hi Alex, My code was working fine before, i have fixed all settings in IE too, but now i am getting this error "Error: Automation server can't create object"

  4. Thanks for the post. Do you know if you can set the regardingobjectid of the email message using this method so that it will properly be tracked if they send the message?

    1. Hi Curtis - so since this email will be in outlook it will not have the regarding object id populated. Now if the user has the outlook crm client they can click track in crm OR you can have your system setup for auto tracking.

  5. I have tried to get this to work on CRM 2015 on premise. Not succesfull yet. Does anyone know if this works on CRM 2015 RU 1? Getting this error "Error: Automation server can't create object".
    I have tried to put it into a button on the ribbon with the CRM Ribbon Workbench - and as a test to put it in an on-save event. Neither works.
    I would love to see an example where emails open in Outlook. Either on premise or CRM Online.

    1. Hi Marianne - were you using IE ? IF so, add your crm's url to your list of trusted sites. Depending on your companies policies we have seen policies that do not allow activeX unless the site is running under trusted or local intranet sites.

  6. I am facing this issue "Automation server can't create object"
    we are using MS CRM 2015 on-prem.
    please help me on this

PowerObjects Recommends