SendGrid v3 REST API PowerShell module for sending automated emails via SendGrid.
- SendGrid basic tier environment at least.
- SendGrid API key with at least these scopes:
- api_keys.create
- api_keys.delete
- api_keys.read
- api_keys.update
- mail.send
Install-Module SGMailer
"API key with API key creation privilege" | New-SGToken | Install-SGToken
After Install-Token, a new PS session is needed!
Send-SGMail -From john.doe@example.com -To jane.doe@example.com -Subject "Confession" -Body "<p><b>LOVE</b> <i>you!</i></p>"
Send-SGMail
Sends an email via SendGrid REST API v3.
Send-SGEmail [-From] <String> [-To] <String> [-Subject] <String> [-NoHTML] [[-SendGridToken] <String>] [-Body] <String> [<CommonParameters>]
Sends an email via SendGrid REST API v3.
Sender email address.
Recipient email address.
Subject of the email.
If set, email body will be sent as plaint text, not HTML.
Direct input of the SendGrid REST API v3 token. Default: use encrypted token from $env:SendGridToken (which can be installed using Install-SGToken)
Email body as string.
This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
PS > # Send an HTML email Send-SGEmail -From [email protected] -To [email protected] -Subject "Confession" -Body "<p><b>LOVE</b> <i>you!</i></p>"
PS > # Send a plain text email Send-SGEmail -From [email protected] -To [email protected] -Subject "Re: Confession" -Body "Love you too!" -NoHTML
Install-SGToken
Sets the SendGridToken environment variable.
Install-SGToken [-Token] <String> [<CommonParameters>]
Sets the Token parameter as encrypted to the SendGridToken environment variable.
SendGrid token. Should be able to have at least api_keys.create, api_keys.delete, api_keys.read, api_keys.update, mail.send privilege.
This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
PS > Install-SGToken -Token "SG.asdfASDF1234....."
New-SGToken
Gets the SendGridToken via SendGrid REST API v3.
New-SGToken [-AdminToken] <String> [[-APIKeyName] <String>] [<CommonParameters>]
Gets the SendGridToken via SendGrid REST API v3.
SendGrid token with at least api_keys.create, api_keys.delete, api_keys.read, api_keys.update, mail.send privilege.
SendGrid API key name. Give a recognizable name to the API key. Defaults to $env:COMPUTERNAME
This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
PS > New-SGToken -AdminToken "SG.asdfASDF1234....."
PS > New-SGToken -APIKeyName "Johns PC" -AdminToken "SG.asdfASDF1234....."
ConvertTo-SGEncryptedToken
Encrypts token with machine key for later use.
ConvertTo-SGEncryptedToken [-Token] []
Encrypts token with machine key for later use.
Token to be encrypted.
This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
PS > ConvertTo-SGEncryptedToken -Token "SG.asdfASDF1234....."
ConvertFrom-SGEncryptedToken
Decrypts token with machine key.
ConvertFrom-SGEncryptedToken [-Token] []
Decrypts token with machine key.
Token to be decrypted.
This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction, WarningVariable, OutBuffer, PipelineVariable, and OutVariable. For more information, see about_CommonParameters (https://go.microsoft.com/fwlink/?LinkID=113216).
PS > ConvertFrom-SGEncryptedToken -Token "SG.asdfASDF1234....."