Emailing with Powershell

While working on another script, I had to address the requirement of emailing the results via Outlook. I had two solutions (syntax methods) to accomplish this but I found one more effective than the other and I’ll highlight that here.

This method works by creating an object within the Outlook application, although this still works, it will give you a prompt within Outlook that a program is trying to send an email. You have to wait for a progress bar to complete before clicking allow or deny for the email to go through. This takes away from the automated approach for a script.

$Outlook = New-Object -ComObject Outlook.Application
$Mail = $Outlook.CreateItem(0)
$Mail.To = ""
$Mail.Subject = "Test Email"
$Mail.Body = $checkDifference

This method works without any intervention as it does not attempt to create an Outlook object item.

$From = ""
$To = ""
$Subject = "Test Email"
$Body = "Test Body Message
$SMTPServer = ""
$SMTPPort = "25" #This is the default port#
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer


0 0 votes
Article Rating
Notify of
Inline Feedbacks
View all comments