Get the App
SLTechnology News&Howtos  ›  Servers  › 

Windows Trigger Mail Sending Script

Shulou Source: shulou.com Published: 2022-06-03 05:54:12 09月29日 Update

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.

Tags: Mailbox backup script mail maximum valid code task content available through place client client way log time server usefulness problem face-to-face Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Linux Shulou Technology Apple