Answers for "powershell send mail"

0

powershell send mail

# Message
$message = New-Object Net.Mail.MailMessage;
$message.From = $From
$message.To = $To
$message.Subject = $Subject
$message.Body = $Body

# Attachment
$attachment = New-Object Net.Mail.Attachment($Attachment);
$message.Attachments.Add($attachment)

# SMTP
$smtp = New-Object Net.Mail.SmtpClient($SMTPServer, $SMTPPort)
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($username, $password)

# Send mail
$smtp.send($message)

# Clean up
$attachment.Dispose()
$message.Dispose()
$smtp.Dispose()
Posted by: Guest on September-16-2021
1

how to send mail and attachment using powershell

$file = "C:\folder\file.csv"
$att = new-object Net.Mail.Attachment($file)
Posted by: Guest on November-09-2020

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language