繁体   English   中英

Javascript:打开 Outlook 并将附件添加到新电子邮件

[英]Javascript: Open Outlook and add attachments to new email

我正在尝试将附件添加到 Outlook 中的新电子邮件。

如下所示(取自此处):

function sendEmail(){
  try{
    var theApp = new ActiveXObject("Outlook.Application");
    var objNS = theApp.GetNameSpace('MAPI');
    var theMailItem = theApp.CreateItem(0); // value 0 = MailItem
    theMailItem.to = ('test@gmail.com');
    theMailItem.Subject = ('test');
    theMailItem.Body = ('test');
    //theMailItem.Attachments.Add("C\\file.txt");
    theMailItem.display();
   }
    catch (err) {
       alert(err.message);
    } 
}

它正在工作(在 Outlook 中打开新电子邮件窗口并预先填充上述数据),但仅当应该添加附件的行被注释掉时。

如果是未注释的异常,则会抛出“找不到文件”之类的异常,但文件存在。 它可以作为附件手动添加到 Outlook 中。

看起来 Outlooks 试图找到文件,但由于某种原因无法找到。 我尝试使用正斜杠、反斜杠和双反斜杠 - 没有运气。

在 Windows 7 和 8 中测试,结果相同。 它只需要从 IE 工作。

也许有人可以提供对上述代码的修复,或者有向 Outlook 添加附件的工作代码?

或者可能知道一些需要更改的 IE 或 Outlook 设置?

无论如何,非常感谢。

其实我走错了路,所以下面的代码完全可以使用。 它在 Windows 8 和 IE 11 上进行了测试。

当然它只能在 IE 中工作,而不能在其他浏览器上工作。 它会打开一个弹出窗口,询问是否允许运行 ActiveX。

   function sendEmail(){
       try{
          var theApp = new ActiveXObject("Outlook.Application");
          var objNS = theApp.GetNameSpace('MAPI');
          var theMailItem = theApp.CreateItem(0); // value 0 = MailItem
          theMailItem.to = ('test@gmail.com');
          theMailItem.Subject = ('test');
          theMailItem.Body = ('test');
          theMailItem.Attachments.Add("C:\\file.txt");
          theMailItem.display();
      }
      catch (err) {
         alert(err.message);
      } 
   }
       try{
          var theApp = new ActiveXObject("Outlook.Application");
          var objNS = theApp.GetNameSpace('MAPI');
          var theMailItem = theApp.CreateItem(0); // value 0 = MailItem
          theMailItem.to = ('test@gmail.com');
          theMailItem.Subject = ('test');
          theMailItem.Body = ('test');
          theMailItem.Attachments.Add("C:\\file.txt");
          theMailItem.display();
      }
      catch (err) {
         alert(err.message);
      } 
   }

semi colon is missing in the path 


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM