Setting up email action for Task Scheduler with PowerShell - windows

I am setting up Windows Task with PowerShell. I am using New-ScheduledTaskAction command to setup an action but couldn't find the option to send an email.
Is it possible to set email action with PowerShell?

Within your Powershell script you can use the Send-MailMessage command to send email, see here for the syntax.
https://ss64.com/ps/send-mailmessage.html
Just relies on having an SMTP server to send through obviously, but you can construct the subject and body content to be included as variables within your script (eg have a string variable with the content you want to include, and then use that variable when calling the command), plus include attachments if relevant.

Related

How do I check that a Rest call is successful in unix shell script?

I would like to invoke a rest Url from Unix shell and verify that call is successful based on return code.
If the call fails, I would like the details to be stored in a variable.
I have tried various options in cURL.

What is the trigger for Jenkins extended email notification

What is the trigger for Jenkins extended email notification plugin? I have in executed shell of the job path to bash script. And somewhere in this script I have notification:
echo "Disc usage is over 90%"
but after this I have to continue script execution without exiting but right away I need just send an email notification about this event. How can I do this?
There are almost 20 different triggers for e-mail ext. See the advanced button under the e-mail configuration. You can use either a separate script result to trigger e-mail ext or an overall build status at the time when the plugin gets triggered.
The latter better suits your situation, as it can be used along with Text Finder plugin to set the overall build status to Unstable depending on the parsed Disk usage value or whatever you need. Then configure e-mail ext to send e-mail on Unstable.

Why does windows pass full custom url including protocol to handling application?

I am trying to create my own URL protocol to initate a custom application from a URL in our internal CRM.
I have created the following registry entry as such:
REGEDIT4
[HKEY_CLASSES_ROOT\smon1]
#="URL:smon Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\smon1\shell]
[HKEY_CLASSES_ROOT\smon1\shell\open]
[HKEY_CLASSES_ROOT\smon1\shell\open\command]
#="\"C:\\smon.exe\" \"%1\""
I have the following link on my site:
<a href='smon:1955'>1955</a>
I would expect this to pass the variable 1955 to the aplication c:\smon.exe.
However it is passing the entire variable "smon:1955".
Why is it passing everything instead of the variable?
What am I missing here?
Your not missing anything, that's how the handlers work; the whole URI is passed in the command line. Detect and parse it away.
The rationale is presumably that it allows multiple protocols to be associated with the same executable without needing to provide custom discriminatory switches in the command key.
To give an example
An Example
this is passed to the browser and shown in the url bar as http://www.example.com

Automator / AppleScript to process incoming emails in Mac Mail

I'm designing an app that allows users to email me crash reports if my app ever crashes. I'd like to leave Mac Mail running on a computer and when an email comes through, an automator script / AppleScript runs to process the contents of the body of the email.
I've got the entire parsing/processing done in a python script, except I have to manually copy the contents of the email into a file and then run my parser on that file.
What's the best way to set this up so I can the contents of the email be pushed into my parsing script?
Many thanks!
Probably the simplest approach is to define a Mail.app Rule. You can set up filtering conditions to specify the set of incoming email to apply the rule to and among the rule actions you can specify is one to run an AppleScript on incoming messages. Rules are managed with Mail.app Preferences -> Rules. Apple supplies examples of Rule Action scripts with Mac OS X. Look in /Library/Scripts/Mail Scripts/Rule Actions or search the web.
Here's a script that extracts from email into a file using a mail rule: MacScripter / Mail rule script for message export. Might be good for sample code for what you're doing.
Use the Dictionary in Applescript Editor to see the properties of mail and you'll quickly be able to see the properties of any mail message. Here's a quick and dirty example of getting the content of a mail message.
tell application "Mail"
set the_messages to selection
repeat with this_message in the_messages
set mytext to content of this_message
end repeat
end tell
Modify the script linked to above that copies output to a temporary file and then pass that file to your Python script to act on.

Running Pine/Alpine within a Windows PowerShell

I am attempting to move most of my daily working life to a terminal shell. I am a .NET dev so I run on WinXP purely for visual studio (just wait until I get better at Emacs). I would really much like it if I could use an email client within a terminal (either using Console or PowerShell within Console).
From my uni days I know of only pine and so this is what I tried to get for windows. However, I could only find two variants, PC-Pine and Alpine for Windows. Both of these provide the mail functions I want and they can connect to my domain exchange server BUT I cannot get them to launch with the shell I am using (Console with PowerShell).
My question: Is there anyone out there running Windows that uses a console mail client that can run in PowerShell or Console2 which has the same or similar functionality to Pine?
If you want to READ email from either the Windows CMD line or Powershell, your best bet it to try and get one of the UNIX-style Terminal email clients to work using CGYWIN as the front end. You might want to try MUTT or the Softabar CMD EMail Client but I haven't tried either one myself.
However, if all you want is SEND email, then that's easy :)
I use Powershell to send emails using the following snippit. This could very easily be put into a script or pasted into your $Profile file to allow you to send emails on the fly.
$emailFrom = "sender"
$emailTo = "recipient"
$subject = "Your subject"
$body = "Your Message"
$smtpServer = "smtp.server.com"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $body)
You could even wrap this in a "Send-Mail" cmdlet and call it using the parameters whenever you want, for example Send-Mail("ivan#stackoverflow","dbarrett83#stackoverflow","I answered your question","Hey man, answered you question on SO...go check it out. 'n. Talk to you later - Dan"). Just make sure to use 'n (the accent key under the tilde followed by the lowercase 'n') for line breaks.
I hope this helps!
~Dan

Resources