Page 1 of 1

Sending Mail (silently) via Outlook

PostPosted: Tue Apr 22, 2014 11:19 am
by dpayer
In a corporate environment, you often don't have SMTP servers you can use for applications but all the employees use Outlook and Exchange for email.

I had a project that required sending emails at every step of a process. David@Argentina pointed me to a VBS that worked to do that in Outlook.

I was able to adapt it as a NB function but it requires that Outlook be running (even if only minimized) to actually send the mail. So I created a subroutine to check if Outlook was running (in a known location) and if not I would run it minimized. I called the function from the subroutine and all works well.

The list of addresses this is sent to must be a string with the values separated by a semi-colon.

Hope this is helpful to someone.

Subroutine:
Code: Select all

.see if Outlook is running
Run "cmd.exe" "/c [#34] tasklist | clip[#34]" "RunOnce+Hidden" "" ""
SearchStr "OUTLOOK.EXE" "[Clipboard]" "[foundoutlook]" ""
If "[foundoutlook]" "=" "0"
.if not running and if [outlookloc] hasn't been set yet
     If "[OutlookLOC]" "=" ""
       FileExists "C:\Program Files (x86)\Microsoft Office\Office12\OUTLOOK.EXE" "[FoundOutlook]"
         If "[FoundOutlook]" "=" "True"
           SetVar "[OutlookLOC]" "C:\Program Files (x86)\Microsoft Office\Office12\OUTLOOK.EXE"
          Else
            FileOpenBox "Find Outlook.exe" "OUTLOOK.EXE" "c:\program files (x86)\Microsoft Office\" "[OutlookLOC]" ""
          Endif
      Endif
    Run "[outlookloc]" "" "RunOnce+Minimized" "" ""
Endif

Call "SendMail_via_Outlook" "[Email_Recipients]" "[ESubject]" "[Ebody]"



Function (name:Sendmail_via_Outlook):
Code: Select all
{NeoBook Function}
Version=5.80
Language=VBScript
Param=[%1]|Text|Email addresses, separated by semi colon
Param=[%2]|Text|Email Subject
Param=[%3]|Text|Email Body - in HTML
{End}
Set objOutlook = CreateObject("Outlook.Application")
   Set objMail = objOutlook.CreateItem(0)
   objMail.to = [%1]
   objMail.Subject = [%2]
   objMail.HTMLBody = [%3]

   objMail.Send
   Set objMail = Nothing
   Set objOutlook = Nothing


Re: Sending Mail (silently) via Outlook

PostPosted: Tue Apr 22, 2014 11:36 am
by mishem
C:\Program Files (x86)\Microsoft Office\Office12\OUTLOOK.EXE


[ProgramFiles]Microsoft Office\Office12\OUTLOOK.EXE
?

Re: Sending Mail (silently) via Outlook

PostPosted: Tue Apr 22, 2014 1:21 pm
by dpayer
mishem wrote:
C:\Program Files (x86)\Microsoft Office\Office12\OUTLOOK.EXE


[ProgramFiles]Microsoft Office\Office12\OUTLOOK.EXE
?


ProgramFiles variable. I am not sure if it uses c:\program files OR c:\program files (x86)

I did a direct link on that subroutine. If it didn't find it the application, it would ask for the user to find it.

David P.

Re: Sending Mail (silently) via Outlook

PostPosted: Thu Apr 24, 2014 3:56 pm
by DaveJ
Hi Dave,

Not sure if this will help but this registry key holds the default mail client including the path

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\mailto\shell\open\command

Mine looks like this ; "C:\PROGRA~2\MICROS~1\Office14\OUTLOOK.EXE" -c IPM.Note /m "%1"

So just run C:\PROGRA~2\MICROS~1\Office14\OUTLOOK.EXE

Good luck

Dave J