gpt4 book ai didi

powershell - 通过Powershell 2.0发送电子邮件

转载 作者:行者123 更新时间:2023-12-03 01:10:15 26 4
gpt4 key购买 nike

我如何通过使用SMTP服务器(例如xxx.xxx.xx.xxx:xx)的 IP地址和端口号匿名身份验证来发送Powershell(v 2.0)脚本的结果,而不这样做需要安全连接吗?

最佳答案

这是一个小脚本,请记住,您位于.NET Framework的顶部:

Param([string[]] $to = $(throw "Please Specify a destination !"),
[string] $subject = "<No Subject>",
[string] $body = $(throw "Pleasr specify a content !"),
[string] $smtpHost = $(throw "Please specify a SMTP server !"),
[string] $from = $(throw "Please specify from email address !")
)

## Message creation
$email = New-Object System.Net.Mail.MailMessage

## Fill the fields
foreach($mailTo in $to)
{
$email.To.Add($mailTo)
}

$email.From = $from
$email.Subject = $subject
$email.Body = $body

## Send the message
$client = New-Object System.Net.Mail.SmtpClient $smtpHost
$client.UseDefaultCredentials = $true
$client.Send($email)

关于powershell - 通过Powershell 2.0发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40464562/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com