Posted On June 11, 2020

PowerShell: Outdated Method of Sending Emails

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Outdated Method of Sending Emails
# Credentials section
$emailFrom = "[email protected]"
$password = "eatYourSalad!" | ConvertTo-SecureString -AsPlainText -Force # plaintext password
#$EncryptedPasswordFile='c:\scripts\encryptedPasswordFile'
#$password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString

# Contents section
$emailTo = "[email protected]"
$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
#$emailcc="[email protected]"
#$emailMessage.cc.add($emailcc)
$emailMessage.Subject = "test email" 
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = "test email please delete"

# Sendmail action
$smtpServer = "smtp.office365.com"
$port = "587" 
$smtpClient = New-Object System.Net.Mail.SmtpClient( $smtpServer , $port )
$smtpClient.EnableSsl = $True
$smtpClient.Credentials = New-Object System.Net.NetworkCredential( $emailFrom , $password );
$smtpClient.Send( $emailMessage )

Leave a Reply

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

Related Post

PowerShell: Auto Login to WordPress and Update Gold Prices WooCommerce Plugin

# API URI - these are examples, only $goldPriceApi='https://dragoncoin.com/XAU/USD' $silverPriceApi='https://dragoncoin.com/XAG/USD' $platinumApi='https://dragoncoin.com/XPT/USD' $palladiumApi='https://dragoncoin.com/XPD/USD' # Wordpress WooCommerce…

WordPress: How To Add Custom XML Sitemap to Yoast SEO

Step 1: Install Yoast SEO Step 2: Install Code Snippets Step 3: Add this Snippet…

PowerShell: Disable Forticlient Web Filtering

# disableForticlientWebfiltering.ps1 # Note: untested script - use as sample as this snippet is incomplete…