Javascript: Open Outlook and add attachments to new email -
i trying add attachment new email in outlook.
like below (taken 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 working (new email window opened in outlook , prefilled above data), when line supposed add attachment commented out.
in case uncommented exception thrown "file cannot found", file exist. can manually added in outlook attachment.
it looks outlooks trying find file cannot reason. tried forward slash, backslash, , double backslash -- no luck.
tested in windows 7 , 8 same result. required work ie.
maybe can provide fix above code or have working piece of code adds attachment outlook?
or may aware of ie or outlook settings need changed?
a lot of thanks, anyway.
actually had wrong path, code below working , can used. tested on windows 8 , ie 11.
sure work in ie , opens popup window asking permission 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); } }
Comments
Post a Comment