I have a script to send email via powershell, sometimes due to the bad network, the send maybe failed.
is there any way to add retry function in it?
thank you
$UserName = "[email protected]" #account
$Password = ConvertTo-SecureString SFDSFWSDSFSFW -AsPlainText –Force #password
$cred = New-Object System.Management.Automation.PSCredential($UserName,$Password) #password
$from = new-object System.Net.Mail.MailAddress("[email protected]", "SCM")
$TLS12Protocol = [System.Net.SecurityProtocolType] 'Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $TLS12Protocol
## 1 send to V290
## Define the Send-MailMessage parameters
$mailParams = @{
SmtpServer = 'smtp.office365.com'
Port = '587' # or '25' if not using TLS
UseSSL = $true ## or not if using non-TLS
BodyasHtml = $true
Credential = $cred
From = $from
To = '[email protected]'
Cc = '[email protected]','[email protected]'
Subject = "AR Report"
Body = 'Dears,'
Attachments = 'C:\AutoJob\xxx\Output_Files\V290.xlsx'
Encoding = $encoding
}
Send-MailMessage @mailParams
it can have retry function to send the email again