# Email Preview And Attachment

Email Preview And Attachment on Evotec with practical examples, usage guidance, and reusable project workflows.

Project

PSWriteHTML

Generate HTML reports, dashboards, and emails from PowerShell without writing HTML, CSS, or JavaScript.

[View on GitHub](https://github.com/EvotecIT/PSWriteHTML) [Visit Website](#) [Releases](https://github.com/EvotecIT/PSWriteHTML/releases/tag/v1.41.0) [Changelog](#) [Get package](https://www.powershellgallery.com/packages/PSWriteHTML)

Stars**1025**

Forks**115**

Open issues**11**

PowerShell Gallery downloads**7576901**

Release**v1.45.0**

Language: PowerShell Updated: 2026-11-18

Curated Examples

An example script from the PSWriteHTML repository.

- Source repository: [https://github.com/EvotecIT/PSWriteHTML](https://github.com/EvotecIT/PSWriteHTML)
- Example group: `Example-Emails`

```powershell
Import-Module (Join-Path $PSScriptRoot '../../PSWriteHTML.psd1') -Force

$Requests = 1..25 | ForEach-Object {
    [pscustomobject]@{
        Ticket = "SR-$_"
        State  = if ($_ % 3 -eq 0) { 'Closed' } else { 'Open' }
    }
}
$ReportPath = Join-Path $PSScriptRoot 'Requests.html'
$Subject = 'Service request summary'

# Generate the attachment separately so it contains all rows and interactive exports.
New-HTML -FilePath $ReportPath -TitleText $Subject {
    New-HTMLTable -DataTable $Requests -Title $Subject {
        New-TableButtonExcel -Title 'Service requests workbook'
        New-TableButtonPDF -Title 'Service requests report'
    }
}

# Generate the preview locally; no mail transport is needed.
$EmailContent = {
    EmailBody {
        EmailText -Text 'The first 10 requests are shown below. The attachment contains the full report.'
        EmailTable -DataTable ($Requests | Select-Object -First 10) -HideFooter
    }
}
$Preview = & $EmailContent
Save-HTML -FilePath (Join-Path $PSScriptRoot 'Requests-preview.html') -HTML $Preview

# To send, supply your mail settings and configured transport. For example:
# Email -From $From -To $To -Server $SmtpServer -Subject $Subject -Attachment $ReportPath -WhatIf $EmailContent
```

<!-- PowerForge markdown artifact sha256:853F4A8B4014FCE9C2E9B6DD1AE9D3CEB21C2813C7B37D83584012A48C1E26C4 -->
