### Install and Import PSSendGrid Module Source: https://context7.com/ba4bes/pssendgrid/llms.txt Installs the PSSendGrid module from the PowerShell Gallery, imports it, and verifies the installation by checking for the `Send-PSSendGridMail` command. ```powershell # Install from PowerShell Gallery Install-Module -Name PSSendGrid -Scope CurrentUser # Import the module Import-Module PSSendGrid # Verify installation Get-Command -Module PSSendGrid # Output: Send-PSSendGridMail ``` -------------------------------- ### Send Plain Text Email with SendGrid Source: https://github.com/ba4bes/pssendgrid/blob/main/docs/Send-PSSendGridMail.md Use this example to send a basic plain text email. Ensure all required parameters like 'FromAddress', 'ToAddress', 'Subject', and 'Token' are provided. ```powershell $Parameters = @{ FromAddress = "example@example.com" ToAddress = "example2@example.com" Subject = "SendGrid example" Body = "This is a plain text email" Token = "adfdasfaihghaweoigneawfaewfawefadfdsfsd4tg45h54hfawfawfawef" FromName = "Jane Doe" ToName = "John Doe" } Send-PSSendGridMail @Parameters ``` -------------------------------- ### Send HTML Email with Inline Attachment using SendGrid Source: https://github.com/ba4bes/pssendgrid/blob/main/docs/Send-PSSendGridMail.md This example demonstrates sending an HTML formatted email with an inline image attachment. The 'AttachmentID' must match the 'cid:' reference in the HTML body. ```powershell $Parameters = @{ Token = "API TOKEN" ToAddress = "example@example.com" BodyAsHTML = "

MetHTML

" ToName = "Example2" FromName = "Example1" FromAddress = "example2@example.com" AttachmentID = "exampleID" AttachmentPath = "C:\temp\exampleimage.jpg" AttachmentDisposition = "inline" Subject = "Test" } Send-PSSendGridMail @Parameters ``` -------------------------------- ### Send Email to Multiple Recipients with CC using SendGrid Source: https://github.com/ba4bes/pssendgrid/blob/main/docs/Send-PSSendGridMail.md This example shows how to send an email to multiple 'To' recipients and include a 'CC' recipient. Ensure arrays are used for multiple addresses and names. ```powershell $Parameters = @{ FromAddress = "example@example.com" ToAddress = @("example2@example.com", "example3@example.com") cCAddress = "Example4@example.com" Subject = "SendGrid example" Body = "This is a plain text email" Token = "adfdasfaihghaweoigneawfaewfawefadfdsfsd4tg45h54hfawfawfawef" FromName = "Jane Doe" ToName = @("John Doe", "Bert Doe") } Send-PSSendGridMail @Parameters ``` -------------------------------- ### Preview Email Sending with -WhatIf Source: https://context7.com/ba4bes/pssendgrid/llms.txt Use -WhatIf to verify parameters before any email is actually sent. This supports ShouldProcess for safe testing. ```powershell $params = @{ FromAddress = "sender@example.com" ToAddress = "recipient@example.com" Subject = "Test" Body = "Dry-run check" Token = $env:SENDGRID_API_KEY } Send-PSSendGridMail @params -WhatIf # Output: What if: An email will be sent from sender@example.com to recipient@example.com # with subject: Test # No HTTP call is made. ``` -------------------------------- ### Enable Detailed Logging with -Verbose Source: https://context7.com/ba4bes/pssendgrid/llms.txt Use -Verbose for detailed execution logging, which is helpful for auditing and debugging in automation pipelines. ```powershell $params = @{ FromAddress = "sender@example.com" ToAddress = "recipient@example.com" Subject = "Verbose demo" Body = "Checking verbose output." Token = $env:SENDGRID_API_KEY } Send-PSSendGridMail @params -Verbose # VERBOSE: Starting Function Send-PSSendGridMail # VERBOSE: Found no BodyAsHTML parameter, Type is set to text/plain # VERBOSE: Found 1 addresses # VERBOSE: Processing Address 0 Value: recipient@example.com # VERBOSE: Creating SendGrid object # VERBOSE: adding subject: Verbose demo # VERBOSE: API has been called, function is done ``` -------------------------------- ### Send HTML Email with PSSendGrid Source: https://context7.com/ba4bes/pssendgrid/llms.txt Sends an email with an HTML body using the `-BodyAsHTML` parameter. The `-Body` parameter is ignored when `-BodyAsHTML` is used, and the content type is automatically set to `text/HTML`. ```powershell $htmlBody = @"

Monthly Report

Please find the summary attached.

Regards,
Automation Team

"@ $params = @{ FromAddress = "reports@example.com" FromName = "Automation Team" ToAddress = "manager@example.com" ToName = "Alice Smith" Subject = "Monthly Report - $(Get-Date -Format 'MMMM yyyy')" BodyAsHTML = $htmlBody Token = $env:SENDGRID_API_KEY } Send-PSSendGridMail @params ``` -------------------------------- ### Send Email with File Attachments Source: https://context7.com/ba4bes/pssendgrid/llms.txt Attaches one or more files to an email using the `-AttachmentPath` parameter. Files are automatically Base64-encoded, and MIME types are inferred from file extensions. Non-image files use `Application/`, while images use `image/`. ```powershell $params = @{ FromAddress = "sender@example.com" ToAddress = "recipient@example.com" Subject = "Files attached" Body = "Please review the attached documents." Token = $env:SENDGRID_API_KEY AttachmentPath = @( "C:\Reports\summary.pdf", "C:\Reports\data.xlsx" ) } Send-PSSendGridMail @params # Both files are Base64-encoded and sent as standard attachments (disposition: attachment). ``` -------------------------------- ### Send Plain Text Email with PSSendGrid Source: https://context7.com/ba4bes/pssendgrid/llms.txt Sends a plain text email to a single recipient using the `Send-PSSendGridMail` function. Requires mandatory parameters like `FromAddress`, `ToAddress`, `Subject`, and `Token`. Use `-Verbose` for detailed output. ```powershell $params = @{ FromAddress = "sender@example.com" FromName = "Jane Doe" ToAddress = "recipient@example.com" ToName = "John Doe" Subject = "Hello from PSSendGrid" Body = "This is a plain text email sent via PowerShell." Token = $env:SENDGRID_API_KEY } Send-PSSendGridMail @params # A successful call returns nothing (HTTP 202 Accepted from SendGrid). # Use -Verbose to see step-by-step progress. ``` -------------------------------- ### Send Email Using EU SendGrid Endpoint Source: https://context7.com/ba4bes/pssendgrid/llms.txt Override the default global endpoint with -ApiEndpoint when your SendGrid account is provisioned on the EU region. ```powershell $params = @{ FromAddress = "sender@example.com" ToAddress = "recipient@example.com" Subject = "EU region email" Body = "Sent via the EU SendGrid endpoint." Token = $env:SENDGRID_API_KEY ApiEndpoint = "https://api.eu.sendgrid.com/v3/mail/send" } Send-PSSendGridMail @params ``` -------------------------------- ### Send Email to Multiple Recipients with CC and BCC Source: https://context7.com/ba4bes/pssendgrid/llms.txt Sends an email to multiple recipients, including CC and BCC addresses. The `-ToAddress`, `-ToName`, `-CCAddress`, `-CCName`, `-BCCAddress`, and `-BCCName` parameters accept arrays. Name arrays must correspond to their respective address arrays. ```powershell $params = @{ FromAddress = "notifications@example.com" FromName = "Notification Service" ToAddress = @("alice@example.com", "bob@example.com") ToName = @("Alice Smith", "Bob Jones") CCAddress = @("carol@example.com") CCName = @("Carol White") BCCAddress = @("audit@example.com") Subject = "Team Notification" Body = "This message was sent to multiple recipients." Token = $env:SENDGRID_API_KEY } Send-PSSendGridMail @params # Alice and Bob receive the email; Carol is CC'd; audit@example.com is BCC'd. ``` -------------------------------- ### Send-PSSendGridMail Source: https://github.com/ba4bes/pssendgrid/blob/main/docs/Send-PSSendGridMail.md This function sends an email using the SendGrid API. It supports various parameters for recipients, sender information, subject, body (plain text or HTML), API token, and attachments. ```APIDOC ## Send-PSSendGridMail ### Description Sends an email through the SendGrid API. Supports plain text or HTML bodies and attachments. ### Syntax ```powershell Send-PSSendGridMail [-ToAddress] [[-ToName] ] [-FromAddress] [[-FromName] ] [[-CCAddress] ] [[-CCName] ] [[-BCCAddress] ] [[-BCCName] ] [-Subject] [[-Body] ] [[-BodyAsHTML] ] [-Token] [[-ApiEndpoint] ] [[-AttachmentPath] ] [[-AttachmentDisposition] ] [[-AttachmentID] ] [-ProgressAction ] [-WhatIf] [-Confirm] [] ``` ### Parameters #### -ToAddress * **Type**: String[] * **Required**: True * **Description**: Email address(es) of the recipient(s). Multiple addresses can be entered in an array. #### -ToName * **Type**: String[] * **Required**: False * **Description**: Name(s) of the recipient(s). If multiple addresses are used, the ToName array must correspond in order to the ToAddress array. #### -FromAddress * **Type**: String * **Required**: True * **Description**: The source email address. #### -FromName * **Type**: String * **Required**: False * **Description**: The source name. #### -CCAddress * **Type**: String[] * **Required**: False * **Description**: Email address(es) of the CC recipient(s). Multiple addresses can be entered in an array. #### -CCName * **Type**: String[] * **Required**: False * **Description**: Name(s) of the CC recipient(s). If multiple addresses are used, the CCName array must correspond in order to the CCAddress array. #### -BCCAddress * **Type**: String[] * **Required**: False * **Description**: Email address(es) of the BCC recipient(s). Multiple addresses can be entered in an array. #### -BCCName * **Type**: String[] * **Required**: False * **Description**: Name(s) of the BCC recipient(s). If multiple addresses are used, the BCCName array must correspond in order to the BCCAddress array. #### -Subject * **Type**: String * **Required**: True * **Description**: The subject of the email. #### -Body * **Type**: String * **Required**: False * **Description**: The plain text content of the email body. #### -BodyAsHTML * **Type**: String * **Required**: False * **Description**: The HTML content of the email body. #### -Token * **Type**: String * **Required**: True * **Description**: Your SendGrid API token. #### -ApiEndpoint * **Type**: Uri * **Required**: False * **Description**: The API endpoint for SendGrid. Defaults to the standard SendGrid API endpoint. #### -AttachmentPath * **Type**: String[] * **Required**: False * **Description**: Path(s) to the file(s) to be attached to the email. #### -AttachmentDisposition * **Type**: String * **Required**: False * **Description**: Disposition of the attachment (e.g., 'inline' for embedding in HTML). #### -AttachmentID * **Type**: String[] * **Required**: False * **Description**: ID(s) for attachments, typically used for inline attachments referenced in the HTML body (e.g., 'cid:exampleID'). ### Examples #### Example 1: Sending a plain text email ```powershell $Parameters = @{ FromAddress = "example@example.com" ToAddress = "example2@example.com" Subject = "SendGrid example" Body = "This is a plain text email" Token = "adfdasfaihghaweoigneawfaewfawefadfdsfsd4tg45h54hfawfawfawef" FromName = "Jane Doe" ToName = "John Doe" } Send-PSSendGridMail @Parameters ``` *Description*: Sends an email from example@example.com to example2@example.com. ``` ```APIDOC #### Example 2: Sending an email with an inline HTML attachment ```powershell $Parameters = @{ Token = "API TOKEN" ToAddress = "example@example.com" BodyAsHTML = "

MetHTML

" ToName = "Example2" FromName = "Example1" FromAddress = "example2@example.com" AttachmentID = "exampleID" AttachmentPath = "C:\temp\exampleimage.jpg" AttachmentDisposition = "inline" Subject = "Test" } Send-PSSendGridMail @Parameters ``` *Description*: Sends an email with an inline attachment in the HTML. ``` ```APIDOC #### Example 3: Sending an email with multiple recipients and CC ```powershell $Parameters = @{ FromAddress = "example@example.com" ToAddress = @("example2@example.com", "example3@example.com") cCAddress = "Example4@example.com" Subject = "SendGrid example" Body = "This is a plain text email" Token = "adfdasfaihghaweoigneawfaewfawefadfdsfsd4tg45h54hfawfawfawef" FromName = "Jane Doe" ToName = @("John Doe", "Bert Doe") } Send-PSSendGridMail @Parameters ``` *Description*: Sends an email from example@example.com to example2@example.com and example3@example.com, with CC to Example4@example.com. ``` -------------------------------- ### Send HTML Email with Inline Image Source: https://context7.com/ba4bes/pssendgrid/llms.txt Embeds an image within an HTML email body by setting `-AttachmentDisposition` to `"inline"` and providing a matching `-AttachmentID`. The image is referenced in the HTML using a `cid:` URI. ```powershell $params = @{ FromAddress = "sender@example.com" ToAddress = "recipient@example.com" Subject = "Look at this chart" BodyAsHTML = "

Results

" Token = $env:SENDGRID_API_KEY AttachmentPath = "C:\Charts\results.png" AttachmentDisposition = "inline" AttachmentID = "chart01" } Send-PSSendGridMail @params ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.