title: How to send an email from an Excel Add-in (js)
body: <p>I'm trying to convert a VBA macro I use extensively to JS/HTML.   It takes the current selected range, checks if the contents look like email addresses, and then composes an email to those people.   </p>
  
  <p>I've got the framework working, but can't find out how to send an email from my Excel addin.   I can't seem to access the Outlook api (office.mailbox) from an Excel host.   </p>
  
  <p>Using mailto works but has a size limit which isn't sufficient because I'm specifying long bodies and possibly hundreds of recipients.</p>
  
  <pre><code>window.location.href = "mailto:user@example.com
  </code></pre>
  
  <p>In VBA the macro looks like this:</p>
  
  <pre><code>Sub EmailSelected()
      Dim OutlookApp As Object
      Dim Mess As Object, Recip As String
      Dim selRange As Range
      ' If there is only one cell selected, don't call SpecialCells, it messes up
      If selection.Count = 1 Then
          Set selRange = selection
      Else
          Set selRange = selection.SpecialCells(xlCellTypeVisible)
      End If
  
      ' If the first cell contains an email address, send as email.
      If InStr(selRange.Item(1).Value, "@") &gt; 0 Then
          For Each c In selRange.Cells
              Recip = Recip &amp; c.Value &amp; ";"
          Next
          Set OutlookApp = CreateObject("Outlook.Application")
          Set Mess = OutlookApp.CreateItem(olMailItem)
          If selRange.Count = 1 Then
              Mess.To = Recip
          Else
              Mess.BCC = Recip
          End If
  
          Mess.Display
      Else
          ' google the cell contents
          For Each c In selRange.Cells
              Recip = Recip &amp; c.Value &amp; " "
          Next
          ActiveWorkbook.FollowHyperlink ("http://www.google.ca/search?q=" &amp; Recip)
      End If
  End Sub
  </code></pre>
  
  <p>Another option would be calling the macro from my excel add-in (suboptimal but could work).  However I can't find a way to do this either.  Any thoughts?</p>