gpt4 book ai didi

powershell - 如何使用powershell v1发送带附件的电子邮件?

转载 作者:行者123 更新时间:2023-12-04 01:56:55 26 4
gpt4 key购买 nike

如何使用powershell v1发送带附件的电子邮件?

最佳答案

这个功能对我来说效果很好。 . .

function send-emailwithattachment( [string] $subject, [string] $body, [object] $to, [Object] $attachment  )
{
$from = "sender.address@domain.com"
$domain = "smtp-server.domain.com"

$mail = new-object System.Net.Mail.MailMessage

for($i=0; $i -lt $to.Length; $i++) {
$mail.To.Add($to[$i]);
}

$mail.From = new-object System.Net.Mail.MailAddress($from)
$mail.Subject = $subject
$mail.Body = $body

$attach = New-Object System.Net.Mail.Attachment($attachment)
$mail.Attachments.Add($attach)

$smtp = new-object System.Net.Mail.SmtpClient($domain)
$smtp.Send($mail)

$attach.Dispose()
$mail.Dispose()
}

关于powershell - 如何使用powershell v1发送带附件的电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2652359/

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