en-US/about_SendgridTools.help.txt
|
TOPIC about_SendGridTools SHORT DESCRIPTION Manage SendGrid from PowerShell through the SendGrid v3 Web API. LONG DESCRIPTION SendGridTools is a PowerShell module that wraps the SendGrid v3 Web API. It covers these areas: - Mail: send messages (Send-SGMailMessage) and read email activity (Get-SGEmailActivity). - Suppressions: suppression groups, group members and global suppressions. - Bounces, blocks, spam reports and invalid emails: list and remove entries. - Authenticated domains and branded (link branding) domains: create, verify, change and remove. - Subusers: create, enable, disable and remove. - API keys: list, create, change and remove. - Alerts: create, change and remove. - Settings: mail, bounce purge, forward bounce, forward spam, address allow list and Enforced TLS settings (Get-SGEnforcedTls, Set-SGEnforcedTls). - Teammates (Get-SGTeammate), IP addresses (Get-SGIPAddress), designs (Get-SGDesign) and permission scopes (Get-SGPermissionScopes): read what the account holds. - Invoke-SGCommand: call an endpoint the module has no command for. To list every command, run: Get-Command -Module SendGridTools SIGNING IN Every session starts with Connect-SendGrid. It takes a PSCredential object where the Password field holds the SendGrid API key; the user name is not used. Connect-SendGrid -Force replaces an existing session. Disconnect-SendGrid ends the session. Connect-SendGrid -ApiKey takes the API key as a secure string, so a key from a vault or an environment variable needs no PSCredential; it cannot be combined with -Credential. In a host that cannot prompt (a console host started with -NonInteractive, a Windows service, a scheduled task without a signed-in user, or a runspace without a user interface), Connect-SendGrid without -Credential or -ApiKey fails with an error that names both, and leaves an existing session as it was. An interactive host asks for the key as before. -NonInteractive counts only in the console host: a host with its own user interface (for example Visual Studio Code) asks for the key as before, and a remote session leaves the prompt to the client. On Linux and macOS only -NonInteractive is recognised, because .NET reports every process there as user interactive, so start a cron or systemd job with pwsh -NonInteractive or pass -ApiKey. REGION SendGrid has a global host and an EU host. Connect-SendGrid -Region EU connects to the EU host, for an account that is hosted there. Connect-SendGrid -BaseUri connects to another https base URI; the path /v3 is added when it is missing. -Region and -BaseUri cannot be used together. A new session without them uses the global host, as before; an existing session is refreshed on its own host. -Region or -BaseUri naming another host than the current session starts a new session and asks for the key when -Credential is not given. If that connection fails, no session is left. Get-SGSubuser -IncludeRegion shows the region of each subuser, and Get-SGSubuser -Region All, Global or EU lists only the subusers in that region; this applies to the list, not to a single subuser named with -Username. Get-SGIPAddress -IncludeRegion reads the IP Address Management API, which shows the region of each IP address. Invoke-SGCommand takes a relative path, or a full URL on the session's host. It refuses a URL to another host, so the API key is sent only to the session's host. SESSION LIFETIME A session lasts one hour. Each command that completes a request renews the hour. When the hour passes without use, the next command fails with an error that the session has expired; run Connect-SendGrid -Force. A plain Connect-SendGrid fails the first time, because it tries to refresh the expired session. EXAMPLES Example 1: Sign in PS C:\> $Credential = Get-Credential PS C:\> Connect-SendGrid -Credential $Credential Enter any user name and the API key as the password. Example 2: Sign in to the EU region PS C:\> Connect-SendGrid -Credential $Credential -Region EU Example 3: List authenticated domains with their DNS records PS C:\> Get-SGAuthenticatedDomain -ShowDNS Example 4: Sign in without a prompt PS C:\> $ApiKey = ConvertTo-SecureString -String $env:SENDGRID_API_KEY -AsPlainText -Force PS C:\> Connect-SendGrid -ApiKey $ApiKey Example 5: Send a message PS C:\> $Message = @{ From = '<address>' To = '<address>' Subject = '<subject>' Body = '<text>' } PS C:\> Send-SGMailMessage @Message NOTE: Thank you to all those who contributed to this module, by writing code, sharing opinions, and provided feedback. TROUBLESHOOTING NOTE: If a command fails with an error that the session has expired, run Connect-SendGrid -Force. Look out on the GitHub repository for issues and new releases. SEE ALSO https://github.com/PhilipHaglund/SendGridTools https://www.powershellgallery.com/packages/SendGridTools Get-Command -Module SendGridTools Get-Help Connect-SendGrid KEYWORDS SendGrid, Email, Mail, API, Suppression, Bounce, Subuser, Domain, Authentication, Region, EU |