Sample: Use OOM in an HTML page to create an email with an attachment and display it using Outlook.

Some customers use Outlook Object Model in IE.  This example shows how this might be done.  Note that IE security settings need to be opened up in order to make this work.   I wrote the sample below to troubleshoot issues with this type of usage of OOM.


To get this page to work you will need to allow active X scripting.  Note that this is considered to be a possible security risk, so its not something I would really recommend doing.

Go to Internet Explorer Options

Choose the Security tab.

Select Local Internet

Select Custom Level

Select ActiveX controls and Plug-Ins

Select Initialize and script ActiveX controls not marked as safe for scripting – set to Enable.


Here is a sample page which demonstrates using Outlook from an HTML page:


function test()

var sInfo = "";
document.getElementById("TestResults").innerHTML = "";

var StartTime = new Date()
sInfo += "Start:  " + StartTime + "<br>";

try {
sInfo += "Create Outlook.Application<br>";
var outlook = new ActiveXObject('Outlook.Application');

sInfo += "outlook.CreateItem<br>";
var email = outlook.CreateItem(0);

sInfo += "email.Recipients.Add<br>";
email.Recipients.Add('').Type = 1; //1=To

//subject and attachments
email.Subject = 'Javascript test';

sInfo += "email.Attachments.Add<br>";

sInfo += "email.Display<br>";

//email.x();  Uncomment to check handling a failure.

catch (error)

sInfo += "Error(s) found:<br>";
for (var er in error)
sInfo += "Error:  " + er + ": " + error[er] + "<br>";


var EndTime = new Date()
sInfo += "End:  " + EndTime + "<br>";

document.getElementById("TestResults").innerHTML = sInfo;
Test OOM in an html page<br>
--------------- <br>

<input type="button" onclick="test()" value="Run Test"/>
--------------- <br>
<p id="TestResults"></p>




Skip to main content