Skip to content

Instantly share code, notes, and snippets.

@plambrechtsen
Last active August 22, 2023 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plambrechtsen/138f0295958a421346497119bc9cc266 to your computer and use it in GitHub Desktop.
Save plambrechtsen/138f0295958a421346497119bc9cc266 to your computer and use it in GitHub Desktop.
Send bulk email with outlook including send-as another account using a CSV input with PowerShell
to cc firstname fullname
peter@email.local shared@email.local; manager@email.local Peter Peter Lambrechtsen
$csvpath = ".\BulkEmail.csv"
$attachment = ".\Attachment.pdf"
$sender = 'shared@email.local'
Function Send-Email {
param (
[String]$to,
[String]$cc,
[String]$firstname,
[String]$fullname
)
$body = @"
<html>
<body style="font-family:verdana">
<h1>M&#333;rena $($fullname)</h1><br/>
</body>
<html>
"@
$Outlook = New-Object -ComObject Outlook.Application
$mail = $Outlook.CreateItem(0)
$mail.subject = "IMPORTANT: Spam for $($firstname)"
$mail.SentOnBehalfOfName = $sender
$mail.SendUsingAccount = $Outlook.Session.Accounts | where {$_.DisplayName -eq $sender}
$mail.sender = $sender
$mail.To = $to
$mail.Cc = $cc
$mail.HTMLbody = $body
$attach = Get-ChildItem $attachment
$mail.Attachments.add($attach.FullName)
$mail.Send()
}
Import-Csv $csvpath | Foreach-Object {
Send-Email $_.to $_.cc $_.firstname $_.fullname
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment