locked
How to send an email every 30 minutes in powershell RRS feed

  • Question

  • User-1694925868 posted

    As part of my asp program, my boss wants me to write a program that will send an email every 30 minutes, and every 24 hours to a list of staff.  - Status updates.  Any ideas on how to do this?

    Saturday, August 13, 2011 1:09 PM

All replies

  • User1052258516 posted

    How to send emails with powershell: http://mspowershell.blogspot.com/2006/12/sending-emails-from-powershell.html

    How to schedule a powershell script http://www.searchmarked.com/windows/how-to-schedule-a-windows-powershell-script.php

    Data Access from a powershell script: http://blogs.technet.com/b/heyscriptingguy/archive/2006/10/02/how-can-i-use-windows-powershell-to-pull-records-from-a-microsoft-access-database.aspx

    The above uses an Access database but should work for SQL Server as well.

     

    Saturday, August 13, 2011 1:48 PM
  • User-1094143783 posted
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin -ErrorAction SilentlyContinue
    function Send-MailMessages {
    <#
     
    .SYNOPSIS
    Generate a constant flow of messages for diagnostic purposes.
     
    .DESCRIPTION
    This script is designed to assist in generating email messages for testing external message flow to and from your messaging infrastructure.
    The ability to quickly send a batch of messages with an attachment on a schedule can help track flow issues or to simply be used to confirm mail routing.
     
    .EXAMPLE
    Send-MailMessages -To Test@Test.com -From Admin@Contoso.com -MessageCount 10 -SecondsDelay 10 -AttachmentSizeMB 1
     
    Send 10 emails to Test@Test.com every 10 seconds with a 1MB Attachment
     
    .EXAMPLE
    Send-MailMessages -MessageCount 48 -SecondsDelay 1800
     
    Send an email every 30 minutes for 24 hours.
     
    .LINK
     
     
    .NOTES
    File Name: Send-MailMessages.ps1
    Author: jfrmilner
    Email: jfrmilner@googlemail.com
    Requires: Powershell V2
    Requires: Exchange Managemnent Shell (Only used to auto find the smtpServer)
    Legal: This script is provided "AS IS" with no warranties or guarantees, and confers no rights. You may use, modify, reproduce, and distribute this script file in any way provided that you agree to give the original author credit.
    Version: v1.0 - 2010 Aug 08 - First Version http://poshcode.org/*
    Version: v1.1 - 2012 April 26 - Fixed when only a single HT Server is available. Added check for existing file. Fixed attachment parameter to use varible.
     
    #>
     
    param ( [Parameter(Mandatory=$false)] $To = "Test@WingtipToys.com", [Parameter(Mandatory=$false)] $From = "Postmaster@contoso.com", $AttachmentSizeMB=$null, $MessageCount=2, $SecondsDelay=10 )
     
    $messageParameters = @{
     Body = $null | ConvertTo-Html -Body "<H2> Test Message, Please ignore </H2>" | Out-String
     From = $from
     To = $to
     SmtpServer = @(Get-TransportServer)[0].Name.ToString()
     }
    if ($AttachmentSizeMB) {
     
    if ((Test-Path $Env:TMP\$($AttachmentSizeMB)mbfile.txt) -ne $true) {
     fsutil file createnew $Env:TMP\$($AttachmentSizeMB)mbfile.txt $($AttachmentSizeMB * 1MB)
     }
    $messageParameters.Add("attachment", "$Env:TMP\$($AttachmentSizeMB)mbfile.txt") }
     
    1..$MessageCount | % { sleep -Seconds $secondsDelay ; Send-MailMessage @messageParameters -Subject ("Mailflow Test Email - " + (Get-Date).ToLongTimeString() + " Message " + $_ + " / $MessageCount") -BodyAsHtml }
     
    }
    Sunday, April 21, 2013 4:06 PM