[英]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.