title: Problem creating an email with an attachment in Javascript
body: <p>I'm initiating an email create, by calling the code below, and adding an attachment to it.</p>
  
  <p>I want the user to be able to type in the receipient, and modify the contents of the message, so I'm not sending it immediately.</p>
  
  <p>Why do I get a RangeError the 2nd time the method is called?<br>
  (The first time it works correctly.)</p>
  
  <pre><code>function NewMailItem(p_recipient, p_subject, p_body, p_file, p_attachmentname)
  {
     try 
     {
       var objO = new ActiveXObject('Outlook.Application');
       var objNS = objO.GetNameSpace('MAPI');
       var mItm = objO.CreateItem(0);
       mItm.Display();
       if (p_recipient.length &gt; 0) 
       {
         mItm.To = p_recipient;
       }
       mItm.Subject = p_subject;
       if (p_file.length &gt; 0) 
       {
        var mAts = mItm.Attachments;
        mAts.add(p_file, 1, p_body.length + 1, p_attachmentname);
       }
       mItm.Body = p_body;
       mItm.GetInspector.WindowState = 2;
     } catch(e) 
     { 
       alert('unable to create new mail item'); 
     } 
  }
  </code></pre>
  
  <p>The error is occuring on the mAts.add line. So when it tries to attach the document, it fails.</p>
  
  <p>Also the file name (p_file) is a http address to a image.</p>