gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:17:45 25 4
gpt4 key购买 nike

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

如下所示(取自 here ):

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 中。

看起来 Outlook 试图找到文件,但由于某种原因找不到。我尝试使用正斜杠、反斜杠和双反斜杠——没有成功。

在 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);
}
}

关于Javascript:打开 Outlook 并将附件添加到新电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35229240/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com