I am trying to add attachment to new email in Outlook.
Like below (taken from here):
function sendEmail(){
try{
var theApp = new ActiveXObjec
Actually I had a wrong path, so the code below is fully working and can be used. It tested on Windows 8 and IE 11.
Sure it will work only in IE and not on other browsers. It opens a popup window asking about permission to run 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