I am trying to add attachment to new email in Outlook.
Like below (taken from 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);
}
}
It is working (new email window opened in Outlook and prefilled with above data), but only when line that supposed to add attachment is commented out.
In case it is uncommented exception is thrown like "File cannot be found", but file is exist. It can be manually added in Outlook as attachment.
It looks like Outlooks trying to find file but cannot for some reason. I tried with forward slash, backslash, and double backslash -- no luck.
Tested in Windows 7 and 8 with same result. It required to work only from IE.
Maybe somebody can provide fix to above code or have working piece of code that adds attachment to Outlook?
Or may be aware of some IE or Outlook settings which need to be changed?
A lot of thanks, anyway.