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: Trigger Azure AD Sync on Remote Server as a Domain Admin

# Trigger-AD-Sync.ps1# Requirements: https://blog.kimconnect.com/powershell-install-rsat/## This script does these things:# a. Obtain Domain Admin credential# b.…

Basic JavaScript: Understand String Immutability

// Setupvar myStr = "Jello World";// Only change code below this linemyStr[0] = "H"; //…

PowerShell: How To Make A System App Do Nothing

# How-To-Make-Existing-System-App-Do-Nothing.ps1# Provide variables$hive="REGISTRY::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WORDPAD.EXE"$key="(default)"$value="C:\Windows\dummy.exe"$defaultValue="C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"# Dummy-File-Creator.ps1$dummyFile="C:\Windows\dummy.exe"$output = new-object byte[] 1; (new-object Random).NextBytes($output);[IO.File]::WriteAllBytes($dummyFile, $output);if…
Other project: DragonCoin.com