# ====== EDIT ONLY THESE 3 LINES ====== $SG_KEY = "YOUR_SENDGRID_API_KEY" $SG_TO = "your_to_address@example.com" $SG_FROM = "" # Verified済みのFrom # ====== $payload = @{ personalizations = @( @{ to = @(@{ email = $SG_TO }) subject = "SendGrid PowerShell test" } ) from = @{ email = $SG_FROM } content = @( @{ type = "text/plain" value = "Hello from PowerShell via SendGrid." } ) } | ConvertTo-Json -Depth 10 try { $resp = Invoke-WebRequest ` -Uri "https://api.sendgrid.com/v3/mail/send" ` -Method Post ` -Headers @{ Authorization = "Bearer $SG_KEY" } ` -ContentType "application/json" ` -Body $payload } catch { Write-Host "Error:" $_ }
Copied