4
如何使用powershell v1發送帶附件的電子郵件?如何使用powershell v1發送帶附件的電子郵件?
如何使用powershell v1發送帶附件的電子郵件?如何使用powershell v1發送帶附件的電子郵件?
這個功能對我來說效果很好。 。 。
function send-emailwithattachment([string] $subject, [string] $body, [object] $to, [Object] $attachment )
{
$from = "[email protected]"
$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()
}