[removed] Open Outlook and add attachments to new email

后端 未结 2 1717
误落风尘
误落风尘 2020-12-21 12:29

I am trying to add attachment to new email in Outlook.

Like below (taken from here):

function sendEmail(){
  try{
    var theApp = new ActiveXObjec         


        
相关标签:
2条回答
  • 2020-12-21 12:55

    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);
          } 
       }
    
    0 讨论(0)
  • 2020-12-21 12:56
           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 
    
    
    
    0 讨论(0)
提交回复
热议问题