Send-MailMessage error in elevated mode.

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST SUBSCRIPTION NUMBERS, LICENSE KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
wartech
Posts: 48
Joined: Sun Jan 13, 2008 8:30 pm

Send-MailMessage error in elevated mode.

Post by wartech » Mon Jan 07, 2019 1:33 pm

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2019 v5.6.156
32 or 64 bit version of product: 64
Operating system: Windows 10 v1809
32 or 64 bit OS: 64

*** Please add details and screenshots as needed below. ***

DO NOT POST SUBSCRIPTIONS, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

Not certain this isn't a script problem rather than a PowerShell Studio problem...
I was debugging a script that kept failing at Send-MailMessage:
ERROR: Send-MailMessage : Unable to connect to the remote server

The command is similar to

Code: Select all

Send-MailMessage -From psharpe@work.com `
				 -To $recipient.Email `
				 -Subject "Your Windows password is about to expire" `
				 -BodyAsHtml $body `
				 -SmtpServer mail1.work.com `
				 -DeliveryNotificationOption OnFailure
Eventually I realized I'd left the elevated mode toggle enabled.
When I switched it off, the script worked perfectly.

Just curious - what caused that?

User avatar
Alexander Riedel
Posts: 7052
Joined: Tue May 29, 2007 4:43 pm

Re: Send-MailMessage error in elevated mode.

Post by Alexander Riedel » Mon Jan 07, 2019 1:40 pm

Basically it is a Windows security feature. You cannot cross-call from an elevated process to a non-elevated one or vice versa.
Run notepad and drag a file from Windows Explorer, it works fine.
Now run Notepad elevated and drag and drop from the (non-elevated) File Explorer ... NADA.
Alexander Riedel
SAPIEN Technologies, Inc.