Skip to content

Commit

Permalink
Merge pull request #43 from akunzai/fix-sendgrid-personalization
Browse files Browse the repository at this point in the history
Fix incorrect SendGrid personalizations
  • Loading branch information
akunzai authored Jan 13, 2023
2 parents 71c6e7c + 0eda1f5 commit 78f8fa8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ git pull
Sample output

````markdown
# Windows Secure Auditor: 0.9.0
# Windows Secure Auditor: 0.9.1

## System Information

Expand Down
2 changes: 1 addition & 1 deletion README.zh-TW.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ git pull
範例輸出

````markdown
# Windows Secure Auditor: 0.9.0
# Windows Secure Auditor: 0.9.1

## 系統資訊

Expand Down
2 changes: 1 addition & 1 deletion SecureAuditor.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# RootModule = ''

# Version number of this module.
ModuleVersion = '0.9.0'
ModuleVersion = '0.9.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
18 changes: 15 additions & 3 deletions examples/SecureAuditor-SendGrid.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,27 @@ if ($UseSmtp) {
}

# https://docs.sendgrid.com/api-reference/mail-send/mail-send
[mailaddress]$fromMail = $From
$parameters = @{
subject = $subject
content = @(@{ type = 'text/plain'; value = $body })
from = @{ email = $From }
personalizations = New-Object System.Collections.ArrayList
from = @{ email = $fromMail.Address }
personalizations = @(
@{ to = @() }
)
}

if (![string]::IsNullOrWhiteSpace($fromaddr.DisplayName)) {
$parameters.from.name = $fromaddr.DisplayName
}

foreach ($email in $To) {
[void]$parameters.personalizations.Add(@{ to = @( @{ email = $email } ) })
[mailaddress]$toMail = $email
$recipient = @{ email = $toMail.Address }
if (![string]::IsNullOrWhiteSpace($toMail.DisplayName)) {
$recipient.name = $toMail.DisplayName
}
$parameters.personalizations[0].to += @($recipient)
}

$json = $parameters | ConvertTo-Json -Depth 4 -Compress
Expand Down

0 comments on commit 78f8fa8

Please sign in to comment.