Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 21, 2013 08:06 PM by Tanaka Hiero
Member
400 Points
241 Posts
Aug 13, 2011 05:09 PM|LINK
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?
email powershell
Star
11721 Points
1859 Posts
Aug 13, 2011 05:48 PM|LINK
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.
47 Points
15 Posts
Apr 21, 2013 08:06 PM|LINK
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
-To
Test@Test.com
-From
Admin@Contoso.com
-MessageCount
10
-SecondsDelay
-AttachmentSizeMB
1
Send 10 emails to Test@Test.com every 10 seconds with a 1MB Attachment
48
1800
Send an email every 30 minutes for 24 hours.
.LINK
http://jfrmilner.wordpress.com/2010/08/26/send
-mailmessages
.NOTES
File Name: Send
.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=
$From
"Postmaster@contoso.com"
,
$AttachmentSizeMB
$null
$MessageCount
=2,
$SecondsDelay
=10 )
$messageParameters
= @{
Body =
|
ConvertTo-Html
-Body
"<H2> Test Message, Please ignore </H2>"
Out-String
From =
$from
To =
$to
SmtpServer = @(Get
-TransportServer
)[0].Name.ToString()
}
if (
) {
if ((
Test-Path
$Env
:TMP\$(
)mbfile.txt)
-ne
$true
fsutil file createnew
)mbfile.txt $(
* 1MB)
.Add(
"attachment"
"$Env:TMP\$($AttachmentSizeMB)mbfile.txt"
) }
1..
| % {
sleep
-Seconds
$secondsDelay
; Send
-MailMessage
@messageParameters
-Subject
(
"Mailflow Test Email - "
+ (
Get-Date
).ToLongTimeString() +
" Message "
+ $_ +
" / $MessageCount"
)
-BodyAsHtml
bhbooton
Member
400 Points
241 Posts
How to send an email every 30 minutes in powershell
Aug 13, 2011 05:09 PM|LINK
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?
email powershell
whighfield
Star
11721 Points
1859 Posts
Re: How to send an email every 30 minutes in powershell
Aug 13, 2011 05:48 PM|LINK
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.
email powershell
Blog | I need more space:DropBox Referral
Tanaka Hiero
Member
47 Points
15 Posts
Re: How to send an email every 30 minutes in powershell
Apr 21, 2013 08:06 PM|LINK
Add-PSSnapinMicrosoft.Exchange.Management.PowerShell.Admin-ErrorActionSilentlyContinue</div> <div class="line number2 index1 alt1">function Send-MailMessages{</div> <div class="line number3 index2 alt2"><#</div> <div class="line number4 index3 alt1"> </div> <div class="line number5 index4 alt2">.SYNOPSIS</div> <div class="line number6 index5 alt1">Generate a constant flow of messages for diagnostic purposes.</div> <div class="line number7 index6 alt2"> </div> <div class="line number8 index7 alt1">.DESCRIPTION</div> <div class="line number9 index8 alt2">This script is designed to assist in generating email messages for testing external message flow to and from your messaging infrastructure.</div> <div class="line number10 index9 alt1">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.</div> <div class="line number11 index10 alt2"> </div> <div class="line number12 index11 alt1">.EXAMPLE</div> <div class="line number13 index12 alt2">Send-MailMessages-ToTest@Test.com-FromAdmin@Contoso.com-MessageCount10-SecondsDelay10-AttachmentSizeMB1</div> <div class="line number14 index13 alt1"> </div> <div class="line number15 index14 alt2">Send 10 emails to Test@Test.com every 10 seconds with a 1MB Attachment</div> <div class="line number16 index15 alt1"> </div> <div class="line number17 index16 alt2">.EXAMPLE</div> <div class="line number18 index17 alt1">Send-MailMessages-MessageCount48-SecondsDelay1800</div> <div class="line number19 index18 alt2"> </div> <div class="line number20 index19 alt1">Send an email every 30 minutes for 24 hours.</div> <div class="line number21 index20 alt2"> </div> <div class="line number22 index21 alt1">.LINK</div> <div class="line number23 index22 alt2"> </div> <div class="line number24 index23 alt1">http://jfrmilner.wordpress.com/2010/08/26/send-mailmessages</div> <div class="line number25 index24 alt2"> </div> <div class="line number26 index25 alt1">.NOTES</div> <div class="line number27 index26 alt2">File Name: Send-MailMessages.ps1</div> <div class="line number28 index27 alt1">Author: jfrmilner</div> <div class="line number29 index28 alt2">Email: jfrmilner@googlemail.com</div> <div class="line number30 index29 alt1">Requires: Powershell V2</div> <div class="line number31 index30 alt2">Requires: Exchange Managemnent Shell (Only used to auto find the smtpServer)</div> <div class="line number32 index31 alt1">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.</div> <div class="line number33 index32 alt2">Version: v1.0 - 2010 Aug 08 - First Version http://poshcode.org/*</div> <div class="line number34 index33 alt1">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.</div> <div class="line number35 index34 alt2"> </div> <div class="line number36 index35 alt1">#></div> <div class="line number37 index36 alt2"> </div> <div class="line number38 index37 alt1">param ( [Parameter(Mandatory=$false)]$To="Test@WingtipToys.com", [Parameter(Mandatory=$false)]$From="Postmaster@contoso.com",$AttachmentSizeMB=$null,$MessageCount=2,$SecondsDelay=10 )</div> <div class="line number39 index38 alt2"> </div> <div class="line number40 index39 alt1">$messageParameters= @{</div> <div class="line number41 index40 alt2">Body =$null|ConvertTo-Html-Body"<H2> Test Message, Please ignore </H2>"|Out-String</div> <div class="line number42 index41 alt1">From =$from</div> <div class="line number43 index42 alt2">To =$to</div> <div class="line number44 index43 alt1">SmtpServer = @(Get-TransportServer)[0].Name.ToString()</div> <div class="line number45 index44 alt2">}</div> <div class="line number46 index45 alt1">if ($AttachmentSizeMB) {</div> <div class="line number47 index46 alt2"> </div> <div class="line number48 index47 alt1">if ((Test-Path$Env:TMP\$($AttachmentSizeMB)mbfile.txt)-ne$true) {</div> <div class="line number49 index48 alt2">fsutil file createnew$Env:TMP\$($AttachmentSizeMB)mbfile.txt $($AttachmentSizeMB* 1MB)</div> <div class="line number50 index49 alt1">}</div> <div class="line number51 index50 alt2">$messageParameters.Add("attachment","$Env:TMP\$($AttachmentSizeMB)mbfile.txt") }</div> <div class="line number52 index51 alt1"> </div> <div class="line number53 index52 alt2">1..$MessageCount| % {sleep-Seconds$secondsDelay; Send-MailMessage@messageParameters-Subject("Mailflow Test Email - "+ (Get-Date).ToLongTimeString() +" Message "+ $_ +" / $MessageCount")-BodyAsHtml}</div> <div class="line number54 index53 alt1"> </div> <div class="line number55 index54 alt2">}</div> </div>