Skip to content

Commit 78f8fa8

Browse files
authored
Merge pull request #43 from akunzai/fix-sendgrid-personalization
Fix incorrect SendGrid personalizations
2 parents 71c6e7c + 0eda1f5 commit 78f8fa8

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ git pull
4747
Sample output
4848

4949
````markdown
50-
# Windows Secure Auditor: 0.9.0
50+
# Windows Secure Auditor: 0.9.1
5151

5252
## System Information
5353

README.zh-TW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ git pull
4747
範例輸出
4848

4949
````markdown
50-
# Windows Secure Auditor: 0.9.0
50+
# Windows Secure Auditor: 0.9.1
5151

5252
## 系統資訊
5353

SecureAuditor.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# RootModule = ''
77

88
# Version number of this module.
9-
ModuleVersion = '0.9.0'
9+
ModuleVersion = '0.9.1'
1010

1111
# Supported PSEditions
1212
# CompatiblePSEditions = @()

examples/SecureAuditor-SendGrid.ps1

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,27 @@ if ($UseSmtp) {
4141
}
4242

4343
# https://docs.sendgrid.com/api-reference/mail-send/mail-send
44+
[mailaddress]$fromMail = $From
4445
$parameters = @{
4546
subject = $subject
4647
content = @(@{ type = 'text/plain'; value = $body })
47-
from = @{ email = $From }
48-
personalizations = New-Object System.Collections.ArrayList
48+
from = @{ email = $fromMail.Address }
49+
personalizations = @(
50+
@{ to = @() }
51+
)
52+
}
53+
54+
if (![string]::IsNullOrWhiteSpace($fromaddr.DisplayName)) {
55+
$parameters.from.name = $fromaddr.DisplayName
4956
}
5057

5158
foreach ($email in $To) {
52-
[void]$parameters.personalizations.Add(@{ to = @( @{ email = $email } ) })
59+
[mailaddress]$toMail = $email
60+
$recipient = @{ email = $toMail.Address }
61+
if (![string]::IsNullOrWhiteSpace($toMail.DisplayName)) {
62+
$recipient.name = $toMail.DisplayName
63+
}
64+
$parameters.personalizations[0].to += @($recipient)
5365
}
5466

5567
$json = $parameters | ConvertTo-Json -Depth 4 -Compress

0 commit comments

Comments
 (0)