Posted On March 31, 2019

PowerShell Script to Send Email

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell Script to Send Email

Use this newer method: https://blog.kimconnect.com/powershell-script-to-send-emails/

### Variables section ###
$fromaddress = "[email protected]"
$toaddress = "[email protected]"
$bccaddress = ""
$CCaddress = ""
$Subject = "EDI Incoming Notification"
$body = "Incoming order has been received and our systems have imported it into the ERP system."
$attachment = "\\FILESERVER01\IT\scripts\EDI-Orders.xls"
$attachment2 = "\\FILESERVER01\IT\scripts\EDI-Summary.xls"
$smtpserver = "kimconnect.mail.protection.outlook.com"

### Sending via SMTP ###
$message = new-object System.Net.Mail.MailMessage
$message.From = $fromaddress
$message.To.Add($toaddress)
$message.CC.Add($CCaddress)
$message.Bcc.Add($bccaddress)
$message.IsBodyHtml = $True
$message.Subject = $Subject
$message.Attachments.Add($attachment)
$message.Attachments.Add($attachment2)
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver)
$smtp.Send($message)

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Check Active Directory Username Collisions

$originalCsvFile='C:\Users\rambo\Desktop\Usernames.csv' $newCsvFile='C:\Users\rambo\Desktop\Usernames-processed.csv' function checkUsernameCollisions($originalCsv,$newCsv){ $csvContents=import-csv $originalCsv write-host "Pulling existing records from Active Directory of $env:USERDNSDOMAIN..."…

PowerShell: Use Win-SCP to Download Files from SFTP Server

Version 2: # downloadFilesViaSftp.ps1 # Version 0.0.2 # # Description: # This simple script is…

PowerShell: Disable Windows Hello

function disableWindowsHello{ $regHive='REGISTRY::HKLM\SOFTWARE\Policies\Microsoft\PassportForWork' $refreshEnv=$false if (!(Test-Path $regHive)){ Write-Host "Creating registry path $regHive" New-Item -Path $regHive…