-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendEmail.ps1
18 lines (17 loc) · 1.25 KB
/
sendEmail.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<#
Powershell Script that's designed to be ran from another script to alert of something new when trying to renew Let's Encrypt security certificate(s)
Revised by TechniSolutions (www.techni.solutions) from https://social.technet.microsoft.com/wiki/contents/articles/51506.powershell-automate-and-schedule-task-scheduler-sending-email-and-attachment.aspx to remove the attachment & pass on customizations to communicate which domain is affected and for what reason
#>
$User = "[email protected]"
$File = "C:\Windows\EmailPassword.txt"
$cred=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)
$EmailTo = "[email protected]"
$EmailFrom = "[email protected]"
$Subject = "Certificate Renewal Script info for " + $Args[0]
$Body = "Hello. There was a " + $Args[1] + " for the " + $Args[0] + " domain. Please follow-up ASAP. Thanks!"
$SMTPServer ="smtp.office365.com"
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($cred.UserName, $cred.Password);
$SMTPClient.Send($SMTPMessage)