How to create an email script and set an alarm to it in PowerShell?

Welcome Forums General PowerShell Q&A How to create an email script and set an alarm to it in PowerShell?

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
5 years, 1 month ago.

  • Author
    Posts
  • #11301

    Participant
    Points: 0
    Rank: Member

    I'm making a PowerShell program that involves having a pop-up box appearing at a specific time, while the script is running and when the alarm goes off, alert box will show up onto the screen. For the alarm below, I want it to not only to pop-up, but I want to send an email message after exiting the pop-up. How would I do that?

    function New-Alarm
    {
    param(
    [Parameter(Mandatory=$true,HelpMessage="Enter a time in HH:MM format (e.g. 23:00)")]
    [String]
    $time,

    [Parameter(Mandatory=$true,HelpMessage="Enter the alert box title (e.g. Alert!).")]
    [String]
    $alertBoxTitle,

    [Parameter(Mandatory=$true,HelpMessage="Enter the alert message.")]
    [String]
    $alertBoxMessage
    )

    do
    {
    Start-Sleep -Seconds 1
    }
    until((get-date) -ge (get-date $time))
    # Play system sound:
    [system.media.systemsounds]::Exclamation.play()
    # Display message
    [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
    [System.Windows.Forms.MessageBox]::Show($alertBoxMessage,$alertBoxTitle)
    }

    New-Alarm -time "12:00" -alertBoxTitle "Alert!" -alertBoxMessage "Send an E-Mail to someone"

    I want the email script right here after "Send an E-Mail to someone" pops up onto the screen.

  • #11302

    Member
    Points: 0
    Rank: Member

    Use the Send-MailMessage cmdlet.

  • #11305

    Participant
    Points: 0
    Rank: Member

    Can you show me how to do that? I want to use Gmail to send the message to the receiver.

The topic ‘How to create an email script and set an alarm to it in PowerShell?’ is closed to new replies.