Powerhsell Send Email Using Outlook
Jump to navigation
Jump to search
Purpose
Use Outlook to send email on behalf of user running the script, instead of using smtp.
Example
$file="$ENV:userprofile\Desktop\$samaccountname.csv" try { $body | Export-Csv -LiteralPath $file -NoTypeInformation } catch {clear; echo "Failed to create file, let IT know this failed"; pause; exit} $outlook = New-Object -ComObject Outlook.Application $mail = $outlook.CreateItem(0) $mail.subject = "New User $samaccountname" $mail.body = "See attached for user properties" $mail.to = "someone@somewhere.com" $mail.attachments.add($file) try { $mail.send() } catch {clear; echo "Failed to send email, let IT know this failed"; pause; exit}