Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
195 views
in Technique[技术] by (71.8m points)

javascript - ActiveX - Automation Server Can't Create Object

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...