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: Copy SMB Share Permissions from Legacy Sources

Scenario:Windows 2008 File Servers migration lacks a built-in function to clone Share Permissions - Get-SmbShareAccess…

Use PowerShell to Grant SysAdmin Role to Certain Users

$principle=$env:USERDOMAIN+'\Domain Admins' $sqlServer=$env:computername function includeSqlTools{ $ErrorActionPreference='stop' try{ $trustedPsgallery=(Get-PSRepository PSGallery).InstallationPolicy -eq 'Trusted' if(!$trustedPsgallery){ Set-PSRepository -Name PSGallery…

PowerShell: Obtain Domain Admin Credential

This little snippet is reusable as an appendix to other scripts since Domain Admin access…