简体   繁体   English

使用 PowerShell 为任务计划程序设置 email 操作

[英]Setting up email action for Task Scheduler with PowerShell

I am setting up Windows Task with PowerShell. I am using New-ScheduledTaskAction command to setup an action but couldn't find the option to send an email.我正在使用 PowerShell 设置 Windows 任务。我正在使用New-ScheduledTaskAction命令来设置操作,但找不到发送 email 的选项。

Is it possible to set email action with PowerShell?是否可以用 PowerShell 设置 email 动作?

Within your Powershell script you can use the Send-MailMessage command to send email, see here for the syntax.在您的 Powershell 脚本中,您可以使用 Send-MailMessage 命令发送 email,语法请参见此处。

https://ss64.com/ps/send-mailmessage.html https://ss64.com/ps/send-mailmessage.html

Just relies on having an SMTP server to send through obviously, but you can construct the subject and body content to be included as variables within your script (eg have a string variable with the content you want to include, and then use that variable when calling the command), plus include attachments if relevant.显然只依赖于有一个 SMTP 服务器发送通过,但您可以构建主题和正文内容以作为变量包含在脚本中(例如,有一个包含您要包含的内容的字符串变量,然后在调用时使用该变量命令),加上相关的附件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM