GP SoftwareTwitter
Opus FAQsManualCommandsObjects

Email selected files with Outlook. Code provide, need help with creating a button



The following thread allows you to email selected files with Outlook, however, it only allows send (1) file at a time.

Copy SENDMAIL to Outlook as HTML instead of Plain Text?

To correct this issue, you would create a .vbs file with the code below, then create a shortcut that you place into your windows send to folder. Thus when you right click the selected file(s), you can click send to and select the shortcut.

The following code works on multiple file selections.

I'm trying to implement this within Directory Opus instead of the Send To context menu, but not sure how to do it.

  1. I'm looking to create a button on my toolbar that will run this script on my selected files. Identical to the current button on Directory Opus, but it uses Outlook instead Directory Opus.
  2. I would also like to store the .vbs and shortcut file in my E:\Documents ILO the SendTo folder to prevent administrative issues.

I have tried moving the files and creating a button, but for some reason it is not recognizing the selection and creates an email with no attachments.

Option Explicit
Dim objArgs, OutApp, oNameSpace, oInbox, oEmailItem, olMailItem
Dim a, oAttachments, subjectStr, olFormatHTML
Dim objFSO,strSigFilePath, objSignatureFile, strBuffer
olMailItem = 0
olFormatHTML = 2
Set objArgs = WScript.Arguments 'gets paths of selected files
Set OutApp = CreateObject("Outlook.Application") 'opens Outlook
Set oEmailItem = OutApp.CreateItem(olMailItem) 'opens new email
For a = 0 to objArgs.Count - 1
Set oAttachments = oEmailItem.Attachments.Add(objArgs(a))
subjectStr = subjectStr & Right(objArgs(a),Len(objArgs(a))-(InStrRev(objArgs(a),"\"))) & "<br/>"
If subjectStr = "" then subjectStr = "No Subject "
oEmailItem.Subject = ""
oEmailItem.BodyFormat = olFormatHTML
oEmailItem.HTMLBody = "<body style='font-family:calibri;font-size:14.5px'>" & "<br/><br/>" & "<b><u>Attached files:</b></u><br/>" & Left(subjectStr, len(subjectStr)-2) &  ". "  & strBuffer & "</body>"


Not sure whether you realized this: The line and script above only works outside of DO. The script is meant to be run from command-line like this:
cscript.exe MyEMailScript.vbs pathtoattachment01 pathtoattachment02 ..

You'd need to remove all of the "WScript" and "WScript.Arguments" occurences (this is where the command line params / attachment paths come in) and replace it with objects / variables where DO keeps the selected items in. clickdata.func.sourcetab.selected_files e.g.

You should look up the examples in the documentation, there are some VBS based script buttons you can steal some bits from. The general form/syntax of your button also needs to fit. It must be of type "Script Function" and you need a wrapping OnClick() function as well, but all is very easy to do, you'll see yourself once you look at it.!Documents/Scripting/Script_Functions.htm!Documents/Scripting/Simple_Script_Function.htm!Documents/Scripting/ClickData.htm