Optimize-Email
August 3, 2026 ยท View on GitHub
SYNOPSIS
Cmdlet that inlines CSS for email bodies using PreMailer.Net.
SYNTAX
Body (Default)
Optimize-Email -Body <string> [-BaseUri <uri>] [-RemoveStyleElements] [-IgnoreElements <string>] [-Css <string>] [-CssFilePath <string>] [-StripIdAndClassAttributes] [-RemoveComments] [-PreserveMediaQueries] [-UseEmailFormatter] [-DownloadRemoteCss] [-HttpClient <HttpClient>] [-AddAnalyticsTags] [-AnalyticsSource <string>] [-AnalyticsMedium <string>] [-AnalyticsCampaign <string>] [-AnalyticsContent <string>] [-AnalyticsDomain <string>] [<CommonParameters>]
File
Optimize-Email -Path <string> [-BaseUri <uri>] [-RemoveStyleElements] [-IgnoreElements <string>] [-Css <string>] [-CssFilePath <string>] [-StripIdAndClassAttributes] [-RemoveComments] [-PreserveMediaQueries] [-UseEmailFormatter] [-DownloadRemoteCss] [-HttpClient <HttpClient>] [-AddAnalyticsTags] [-AnalyticsSource <string>] [-AnalyticsMedium <string>] [-AnalyticsCampaign <string>] [-AnalyticsContent <string>] [-AnalyticsDomain <string>] [<CommonParameters>]
DESCRIPTION
Cmdlet that inlines CSS for email bodies using PreMailer.Net.
EXAMPLES
EXAMPLE 1
Optimize-Email -Body $html -RemoveComments
PARAMETERS
-AddAnalyticsTags
Add Google Analytics tags.
Type: SwitchParameter
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-AnalyticsCampaign
Value for utm_campaign.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-AnalyticsContent
Value for utm_content.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-AnalyticsDomain
Analytics domain.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-AnalyticsMedium
Value for utm_medium.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-AnalyticsSource
Value for utm_source.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-BaseUri
Base URI for resolving relative URLs.
Type: Uri
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Body
HTML content to process.
Type: String
Parameter Sets: Body
Aliases: Content
Possible values:
Required: True
Position: named
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
-Css
Additional CSS content to inline.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-CssFilePath
Path to a CSS file to include.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-DownloadRemoteCss
Download CSS from elements.
Type: SwitchParameter
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-HttpClient
HTTP client used to download linked stylesheets. The caller retains ownership of the client.
Type: HttpClient
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-IgnoreElements
CSS selector for elements to ignore.
Type: String
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-Path
Path to a HTML file to process.
Type: String
Parameter Sets: File
Aliases: File
Possible values:
Required: True
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-PreserveMediaQueries
Preserve media queries from style nodes.
Type: SwitchParameter
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-RemoveComments
Remove comments from HTML and CSS.
Type: SwitchParameter
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-RemoveStyleElements
Remove <pre class="shiki github-light" style="background-color:#fff;color:#24292e" tabindex="0"><code><span class="line"><span style="color:#22863A">Type</span><span style="color:#24292E">: </span><span style="color:#032F62">SwitchParameter</span></span> <span class="line"><span style="color:#22863A">Parameter Sets</span><span style="color:#24292E">: </span><span style="color:#032F62">Body, File</span></span> <span class="line"><span style="color:#22863A">Aliases</span><span style="color:#24292E">: </span><span style="color:#032F62">None</span></span> <span class="line"><span style="color:#22863A">Possible values</span><span style="color:#24292E">:</span></span> <span class="line"></span> <span class="line"><span style="color:#22863A">Required</span><span style="color:#24292E">: </span><span style="color:#005CC5">False</span></span> <span class="line"><span style="color:#22863A">Position</span><span style="color:#24292E">: </span><span style="color:#032F62">named</span></span> <span class="line"><span style="color:#22863A">Default value</span><span style="color:#24292E">: </span><span style="color:#032F62">None</span></span> <span class="line"><span style="color:#22863A">Accept pipeline input</span><span style="color:#24292E">: </span><span style="color:#005CC5">False</span></span> <span class="line"><span style="color:#22863A">Accept wildcard characters</span><span style="color:#24292E">: </span><span style="color:#005CC5">False</span></span> <span class="line"></span></code>
-StripIdAndClassAttributes
Strip id and class attributes from output.
Type: SwitchParameter
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
-UseEmailFormatter
Use the email formatter when generating HTML.
Type: SwitchParameter
Parameter Sets: Body, File
Aliases: None
Possible values:
Required: False
Position: named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
INPUTS
System.String
OUTPUTS
System.String
RELATED LINKS
- None