Windows Trigger Mail Sending Script
You can use the following code to execute a bat to send mail under windws:
Powershell.exe-executionpolicy remotesigned-file C:\ AutoSendingMailScript\ sendemail2TACSuLan.ps1
So the script for powershell is:
$EmailFrom = "abc@sulannetXX.com"
$EmailTo = "abc@sulannetXX.com"
$Subject = "* there are some failures in the daily backup plan, please check it out"
$Body = "backup failed, failed through task schdule, pay attention to check, view the contents of task schedule on 172.16.0.7 server through RDP!
If you have any questions, please consult! "
$SMTPServer = "smtp.mxhichina.com"
$SMTPClient = New-Object Net.Mail.SmtpClient ($SmtpServer, 25)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential ("abc@sulannet.com", "XXXXXX")
$SMTPClient.Send ($EmailFrom, $EmailTo, $Subject, $Body)
P.S.
Many mailboxes have been tested, of which Gmail is also okay, but gmal needs to verify the sending client; so the mailbox provided by Aliyun is finally used.
The mailbox for Gmail is as follows:
$EmailFrom = "2323XXX@gmail.com"
$EmailTo = "2323XXX@126.com"
$Subject = "Subject"
$Body = "Body"
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient ($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential ("2323XXX@gmail.com", "PasswordXXX")
$SMTPClient.Send ($EmailFrom, $EmailTo, $Subject, $Body)
The greatest use is:
You can automatically call this script to send an email after a certain time log is triggered by a scheduled task.
Very effective.