Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Windows Trigger Mail Sending Script

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report