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.
FCOASystems AdminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ben Personick (Previously QCubed)Lead SaaS Infrastructure EngineerCommented:
The VB Script methods have not worked natively in ages, you must have installed old .net packages to get those working in 2k8/2012, so I would have thought 2016 would let you fanagle that too, but maybe they've finally removed the chance, have you looked into how you got it to work in 2012?

As for Powershell, you can just call it from inside your VBScript

Dim _SMTPServer as string = "Server IP or FQDN"
Dim _MailFrom as string = "Sending Email"
Dim _RcptTo as string = "Your Email Address@Your"
Dim _Subject as string = "Your Email Subject"
Dim _Body as string = "Just an Example"
Dim _Attachment = "C:\temp\Completely_Optional_Attachment.ext" 

Dim _ShellSession As Object
Set _ShellSession= CreateObject("Wscript.Shell")

'Send WITH Attachment:
_ShellSession.Run("  PowerShell.exe -Command '& {Send-MailMessage -To "&_RcptTo&" -Subject "&_Subject&" -Body ( "&_Body&" | out-string )  -SmtpServer "&_SMTPServer&" -From "&_MailFrom&" -Attachment "&_Attachment&" }}' ")

'Send WITHOUT Attachment:
_ShellSession.Run("  PowerShell.exe -Command '& {Send-MailMessage -To "&_RcptTo&" -Subject "&_Subject&" -Body ( "&_Body&" | out-string )  -SmtpServer "&_SMTPServer&" -From "&_MailFrom&" }}' ")

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.
FCOASystems AdminAuthor Commented:
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.
FCOASystems AdminAuthor Commented:
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.
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Ben Personick (Previously QCubed)Lead SaaS Infrastructure EngineerCommented:
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
FCOASystems AdminAuthor Commented:
The following options work:

Set objShell = CreateObject("Wscript.Shell")
objShell.Run("powershell -NonInteractive -ExecutionPolicy Bypass -Command ""& { Send-MailMessage -To -From -Subject 'Test Message' -Body 'This is a test.' -SMTPServer }""")

Open in new window


strSMTPServer = ""
strFrom = ""
strTo = ""
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 &" }""")

Open in new window

FCOASystems AdminAuthor Commented:
See my code examples about. Much thanks to Ben for pointing me down the right path!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ben Personick (Previously QCubed)Lead SaaS Infrastructure EngineerCommented:
Glad to help!  :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.