Created
December 23, 2025 09:41
-
-
Save eugrus/de759fbce868b51e0d5d57171353168e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $outlook = New-Object -ComObject Outlook.Application | |
| $explorer = $outlook.ActiveExplorer() | |
| $selection = $explorer.Selection | |
| if ($selection.Count -eq 0) { | |
| Write-Error "No email selected." | |
| exit | |
| } | |
| $mail = $selection.Item(1) | |
| $PicturesFolder = [Environment]::GetFolderPath("MyPictures") | |
| $savePath = Join-Path $PicturesFolder "OutlookImages" | |
| if (-not (Test-Path $savePath)) { | |
| New-Item -ItemType Directory -Path $savePath | Out-Null | |
| } | |
| $images = @() | |
| $index = 1 | |
| foreach ($att in $mail.Attachments) { | |
| $ext = [System.IO.Path]::GetExtension($att.FileName).ToLower() | |
| if ($ext -match "\.(jpg|jpeg|png|gif|bmp|webp)") { | |
| $safeName = $att.FileName -replace '[\\/:*?"<>|]', '_' | |
| $imagePath = Join-Path $savePath ("{0:D3}_{1}" -f $index, $safeName) | |
| $att.SaveAsFile($imagePath) | |
| $images += $imagePath | |
| $index++ | |
| } | |
| } | |
| if ($images.Count -eq 0) { | |
| Write-Error "No images found." | |
| exit | |
| } | |
| $outputPdf = Join-Path $savePath "images-from-email.pdf" | |
| #magick @images "$outputPdf" | |
| & magick $images -auto-orient "$outputPdf" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment