FCOA
asked on
Need alternate to CDO.Message for Windows Server Core
Looking for an alternate to CDO.Message for sending email in a VBScript on Windows Server Core.
NOTE: While we also use PowerShell scripts to send email, we have several substantial legacy VBScripts that carry out tasks and send mail, so fully rewriting these in PowerShell will be a longer term objective. In the interim, we're in need of a workaround to the VBScript issue. Thanks.
NOTE: While we also use PowerShell scripts to send email, we have several substantial legacy VBScripts that carry out tasks and send mail, so fully rewriting these in PowerShell will be a longer term objective. In the interim, we're in need of a workaround to the VBScript issue. Thanks.
ASKER
Excellent!! Thanks so much! I'll give this a try.
Interestingly, it appears the CDO.Message method works fine for us through Server 2019 on the "Desktop Experience" version, but not on Server Core. This includes devices with the base install and no add-on roles or features. This is actually our first foray into Server Core.
Interestingly, it appears the CDO.Message method works fine for us through Server 2019 on the "Desktop Experience" version, but not on Server Core. This includes devices with the base install and no add-on roles or features. This is actually our first foray into Server Core.
ASKER
FYI- I've been toying with the suggested VBScript, but it doesn't appear to be working. I started with it as-is, and that didn't work, then tried revising it from there. Thus far, no luck.
To be completely up front we depricated and converted all pf our VB scripting about 10 yeas ago give or take, because of inconsistamcies in each OS's implementation, and mail send cdo not working most specifically.
We've been writing pure cmd scripts and a little powershell, although its finnally flipped to mostly powershell and some cmd, so I had to lift the old school shell execute example, and had no test space.
I can say the body and subject will need quotes around them, which I don't have
are you getting any error? might also need to run elevated, which I recall being possiblr in vb.
finally even in CMD we usually pipe the output to a cmd script that calls the powershell, or nest the powershell in the cmd and call itself, but VBA does not work well for code nesting
We've been writing pure cmd scripts and a little powershell, although its finnally flipped to mostly powershell and some cmd, so I had to lift the old school shell execute example, and had no test space.
I can say the body and subject will need quotes around them, which I don't have
are you getting any error? might also need to run elevated, which I recall being possiblr in vb.
finally even in CMD we usually pipe the output to a cmd script that calls the powershell, or nest the powershell in the cmd and call itself, but VBA does not work well for code nesting
ASKER
The following options work:
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell -NonInteractive -ExecutionPolicy Bypass -Command ""& { Send-MailMessage -To to@domain.com -From from@domain.com -Subject 'Test Message' -Body 'This is a test.' -SMTPServer servermame.domain.com }""")
OR strSMTPServer = "servername.domain.com"
strFrom = "from@domain.com"
strTo = "to@domain.com"
strSubject = "Test Message"
strBody = "This is a test."
Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell -NonInteractive -ExecutionPolicy Bypass -Command ""& { Send-MailMessage -To "& strTo &" -From "& strFrom &" -Subject '"& strSubject &"' -Body '"& strBody &"' -SMTPServer "& strSMTPServer &" }""")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Glad to help! :)
As for Powershell, you can just call it from inside your VBScript
Open in new window
I actually use this similar method from CMD as the majority of my older scripts are CMD, and I have been replacing parts that called VB Script or 3rd party utilities to send email with a call to powershell as needed.