This is very 101-level basic stuff, but only after arriving at the end.  Sort of like smelling something funny in the middle of the night, getting out of bed in the dark to seek out the source, and then turning on the light to realize you already stepped in it.

So, I needed to create an Orchestrator Runbook which includes an activity to send a message via Gmail SMTP/SSL.  I started by adapting this example which sends SMS/MMS via Twilio (read the notes about why the author invokes a PsSession process instead of using the built-in Run PowerShell Script activity).  Stripped out the Twilio stuff, the SMS/MMS/Voice message idiosyncracies (such as message limit, and also the truncate function code).  It works fine. But not at first.

Running the activity and script code via the Runbook Tester, it starts off fine, and then sits for a long time.  After nearly three minutes, it finally crashed with the following error…

Send-MailMessage : Unable to connect to the remote server
At line:11 char:1
+ Send-MailMessage -To $Recipient -From $SenderAddress -SmtpServer $GMailServer -P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
 + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

After hitting my Gmail account, I see this…

ps-gmail-oops

And by the way, if you set up the recommended Google account “recovery” features, it will send an email to that account as well.  It has a subject “Sign-in attempt prevented”.

Following the “learn more” link, it provides yet another link to change the setting…

ps-gmail-oops2

And as before, when you change a security setting in your Google account, it sends another email to your recovery account to notify you, just in case it was someone else being malicious.

So, now the code and the Runbook activity work fine.

Just a hop, skip and a head-bump. Ouch!

Advertisements

One thought on “PowerShell, Orchestrator, Gmail and uh…

  1. Could you have generated an application security key to allow your script to login to your Gmail for the function of sending the mail?

    Under your account settings there is a App Passwords setting that you generate and use in your script the bypasses the dual factor auth (since you generate ti yourself and it is assumed that you want to allow this).

    Just a thought.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s