[Scripts] Send-MailMessage with For loop

課堂上想起來老師曾經提到的Send-MailMessage,就自己用windows 2012 R2 架了一個SMTP Server,然後寫了這一個小script。

$bomb = 2

$From = 'demo@demogmail.com'
$To = 'demo@demogmail.com'
$Subject = 'Hello World!'
$Body = 'I <3<3<3<3<3 Powershell'
$SMTPServer = "localhost"
$SMTPPort = "25"




for($i=1; $i -le $bomb; $i++) {

Send-MailMessage -From $From `
                 -to $To `
                 -Subject $Subject `
                 -Body $Body `
                 -SmtpServer $SMTPServer `
                 -port $SMTPPort
}

Leave a Reply

Your email address will not be published. Required fields are marked *