$server = 'a-.......windows.net'
$dbname = 'summit'
$username='sumuser'
$pwrd = '.......2'
$ConnectionString = ("Server={0};User Id={1};Password={2};Database={3};" -f $server,$username,$pwrd,$dbname)
$sql='SELECT * FROM RegDocMaster'
$dt = New-Object System.Data.DataTable
$da = New-Object System.Data.SqlClient.SqlDataAdapter($Sql,$ConnectionString)
$RecordsAffected = $da.fill($dt)
#1. check out results
#$dt
#initialize an array
$a = @()
# 2. loop through results
ForEach ($row in $dt) {
#$row.pdfurl
#$row.pdfurl.LastIndexOf('.') #place of last . in the string
#if we were working with files we could use get-item and then access the .extension property, but we're working with urls here so
$ext = $row.PdfUrl.Substring($row.pdfurl.LastIndexOf('.')+1)
#$ext
if ($ext -ne 'pdf') {
$a += " $($row.Title) ($($row.PdfUrl)) is not a pdf document"
}
}
#Body of email
$body = "Hey just wanted to let you know:`n"
#Join our array into a body string
$body += $a -join "`n"
$apikey = 'aa3..........f30'
$secretkey = ConvertTo-SecureString '..........0' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($apikey,$secretkey)
$sendMailParams = @{
From = 'noreply@w8.net' #if you're going to use this smtp server, must be @w8.net
To = 'youremail@yourdomain.com'
Subject = '[System Notification] Guess what?'
Body = $body
SMTPServer = 'in-v3.mailjet.com'
Port = 587
Credential = $cred
}
Send-MailMessage @sendMailParams
"check $to to see if message was received."