|
36 | 36 | process |
37 | 37 | { |
38 | 38 | #region Send mails |
39 | | - foreach ($item in (Get-ChildItem -Path (Get-PSFConfigValue -FullName 'MailDaemon.Daemon.MailPickupPath'))) |
| 39 | + foreach ($item in (Get-ChildItem -Path (Get-PSFConfigValue -FullName 'MailDaemon.Daemon.MailPickupPath') -Filter "*.clixml")) |
40 | 40 | { |
41 | 41 | $email = Import-Clixml -Path $item.FullName |
42 | 42 | # Skip emails that should not yet be processed |
|
57 | 57 | else { $parameters["Subject"] = "<no subject>" } |
58 | 58 | if ($email.Body) { $parameters["Body"] = $email.Body } |
59 | 59 | if ($null -ne $email.BodyAsHtml) { $parameters["BodyAsHtml"] = $email.BodyAsHtml } |
60 | | - if ($email.Attachments) { $parameters["Attachments"] = $email.Attachments } |
| 60 | + if ($email.Attachments) { |
| 61 | + if ($email.AttachmentsBinary) { |
| 62 | + $tempAttachmentParentDir = New-Item (join-path $item.Directory $item.BaseName) -Force -ItemType Directory |
| 63 | + $attachmentCounter = 0 |
| 64 | + $parameters["Attachments"] = @() |
| 65 | + # Using multiple subfolders to allow for duplicate attachment names |
| 66 | + foreach ($binaryAttachment in $email.AttachmentsBinary) { |
| 67 | + $tempAttachmentDir = new-item (join-path $tempAttachmentParentDir $attachmentCounter) -Force -ItemType Directory |
| 68 | + $tempAttachmentPath = join-path $tempAttachmentDir $binaryAttachment.Name |
| 69 | + $null = [System.IO.File]::WriteAllBytes($tempAttachmentPath, $binaryAttachment.Data) |
| 70 | + $parameters["Attachments"] = @($parameters["Attachments"]) + $tempAttachmentPath |
| 71 | + $attachmentCounter = $attachmentCounter + 1 |
| 72 | + } |
| 73 | + } else { |
| 74 | + $parameters["Attachments"] = $email.Attachments |
| 75 | + } |
| 76 | + } |
61 | 77 | if ($script:_Config.SenderCredentialPath) { $parameters["Credential"] = Import-Clixml (Get-PSFConfigValue -FullName 'MailDaemon.Daemon.SenderCredentialPath') } |
62 | 78 |
|
63 | 79 | Write-PSFMessage -Level Verbose -String 'Invoke-MDDaemon.SendMail.Start' -StringValues @($email.Taskname, $parameters['Subject'], $parameters['From'], ($parameters['To'] -join ",")) -Target $email.Taskname |
|
73 | 89 | Remove-Item $attachment -Force |
74 | 90 | } |
75 | 91 | } |
| 92 | + # Remove temp deserialized attachments if used |
| 93 | + if ($email.AttachmentsBinary) { |
| 94 | + $null = remove-item -Path $tempAttachmentParentDir -Recurse -Force |
| 95 | + } |
76 | 96 |
|
77 | 97 | # Update the timestamp (the timeout for deletion uses this) and move it to the sent items folder |
78 | 98 | $item.LastWriteTime = Get-Date |
|
0 commit comments