ActiveX - Automation Server Can't Create Object

user70192 picture user70192 · Mar 1, 2011 · Viewed 81.9k times · Source

I have a web page from which I need to send an email to. I need to send a LARGE email from the browser. Because the content is larger than the query string allows, I need to rely on Active X. I want to send this email through Outlook. In an attempt to do this, I've written the following code:

try {
  var to = "";
  var cc = "";
  var subject = "Action Required";
  var body = GenerateEmailBody();

  var outlook = new ActiveXObject('Outlook.Application');
  var outlookNamespace = outlook.GetNameSpace('MAPI');

  var message = outlookNamespace.CreateItem(0);
  message.Display();
  message.To = to;
  message.Subject = subject;
  message.Body = body;
  message.GetInspector.WindowState = 2;
} catch (err) {
  alert("Unable to send email. " + err);
}

When I execute this code, I get the following error:

ReferenceError: ActiveXObject is not defined 

What am I doing wrong?

Thanks!

Answer

epascarello picture epascarello · Mar 1, 2011

The error "Automation Server Can't Create Object" means that your browser's security settings are too low for the ActiveX control to run. You have to move your page into the trusted sites list and lower the ActiveX settings so it can run.

Personally I would avoid ActiveX like the plague since it is locking you into the IE only world. Hence why we still have people stuck with IE6.

It you are trying to just preload a mail message, you can use mailto: