• Writing Script to Run at Shutdown to Send Email

    Home » Forums » AskWoody support » Windows » Windows 10 » Questions: Win10 » Writing Script to Run at Shutdown to Send Email

    Author
    Topic
    #349306

    Windows 10 Pro 1809

    This is my first try at writing a script to run at shutdown using Task Scheduler.

    Basically, I am sending an email from the computer at shutdown to a smart plug to turn off. The task scheduler runs, but the email is not sent. I need some help to find out what I need to change in the script so that it will send the email.

    (I have edited the script for privacy reasons, but everything else is the same. And, I am using AOL for the sending from email address, I would like to keep it AOL)

    Here is the script:
    Send-MailMessage -To xxxxx@whatever.com -Subject “#Off” -Body “none” -SmtpServer smtp.aol.com -From xxxxx@aol.com

    And this is the trigger in the task scheduler:
    Log: System
    Source: User32
    Event ID: 1074

    Thanks and appreciate any help with this.

    Viewing 4 reply threads
    Author
    Replies
    • #349332

      Shutdown probably terminates the email process. It’s be easier to have the script shut the PC down after sending the email instead of using the TS.
      Make sure you allow plenty of time between the shutdown email and the smart plug turning off.

      cheers, Paul

      1 user thanked author for this post.
      • #349442

        Highly likely . . .  shutdown allows only a short time before all remaining processes are terminated (finished or not.)

         

        ~ Group "Weekend" ~

    • #349389

      @tr23i921 , is this a chicken and egg thing? I’m curious if the smart plug you want to shut off is the receptacle providing power to the machine that is turning off the receptacle that is providing power to the…

      If you succeed in turning off the power, does the computer have battery power to complete the shutdown sequence? Or are you counting on the slow delivery of the email to allow the time required? I apologize that I am not familiar with much of the burgeoning IoT market. Does the smart plug rely on the computer itself to network and receive the email, or is the router also powered by this same unit?

      This becomes much less complicated, if for instance you are simply turning off the light in the room.

    • #349433

      The smartplug is not turning off power to the computer. The smartplug is connected to an external fan which is not connected to the computer. There is no connection between the smartplug and the computer power source.

      It should be a simple operation.

      How does the script look? Is it correctly written?

       

    • #349441

      I suspect that AOL is not accepting the SMTP connection.  Last I checked they (like all reputable email hosts) require account authentication to accept an SMTP request.  I don’t see that in your script.

      Secondly I don’t see a port assignment for the SMTP connection.  This is important because these days almost all ISP’s block the default SMTP port: 25, and for good reason.  AOL accepts port 587 for TLS, or 465 for SSL.

      In summary you need an AUTH statement with a valid username and password for AOL, and the correct port assignment for AOL’s auth / SSL request.

      Alternately if you are hosting your own outgoing email server for this function, you need to make sure it’s setup correctly and not a) blacklisted by the various spam lists and b) has a valid reverse IP assignment and SPF record and c) not marked as an open forwarder on the public Internet.  Else AOL will reject anything from your host.

      Email has gotten a lot harder in the last few years . . .  😉

      ~ Group "Weekend" ~

    • #349490

      Here’s what I did.

      Since I’m new to writing scripts, I found a program that sends email by command line. It has a GUI interface and is easy to configure.  It is SwithMail. More info can be found here: https://sourceforge.net/p/swithmail/wiki/Home/

      Task Scheduler however could not send the email using SwithMail when shutting down, I think there probably was not enough time to send the email. So, I will use a keyboard launcher to run SwithMail at shutdown. This solution has worked. The smartplug now turns off when the computer is shutdown.

      Thanks for everyone’s response. I appreciate the effort.

      There was no app for the computer by the manufacturer of the smartplug. Perhaps this post will help others who are trying to communicate with a smartplug from the computer.

    Viewing 4 reply threads
    Reply To: Writing Script to Run at Shutdown to Send Email

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: