Skip to content

Commit 39ee347

Browse files
author
Friedrich Weinmann
committed
1.1.7
1 parent c201c73 commit 39ee347

6 files changed

Lines changed: 36 additions & 41 deletions

File tree

MailDaemon/MailDaemon.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
RootModule = 'MailDaemon.psm1'
44

55
# Version number of this module.
6-
ModuleVersion = '1.1.3'
6+
ModuleVersion = '1.1.7'
77

88
# ID used to uniquely identify this module
99
GUID = 'd5ba333f-5210-4d69-83f0-150dd0909139'

MailDaemon/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## ???
4+
5+
+ Upd: Invoke-MDDaemon - implements `UseSSL` as configured
6+
+ Upd: Set-MDDaemon - supports `-UseSSL`
7+
+ Upd: Install-MDDaemon - supports `-UseSSL`
8+
+ Fix: Install-MDDaemon - now exports credentials without prompting.
9+
310
## 1.1.3 (2024-11-11)
411

512
+ Upd: Added ability to directly embed attachments in the email task, rather than only providing a path to them. (thanks @jebbster88 ; #10)

MailDaemon/functions/Install-MDDaemon.ps1

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
function Install-MDDaemon
2-
{
3-
<#
1+
function Install-MDDaemon {
2+
<#
43
.SYNOPSIS
54
Configures a computer for using the Mail Daemon
65
@@ -103,11 +102,13 @@
103102
$SenderCredential,
104103

105104
[string]
106-
$RecipientDefault
105+
$RecipientDefault,
106+
107+
[switch]
108+
$UseSSL
107109
)
108110

109-
begin
110-
{
111+
begin {
111112
#region Repetitions (ugly)
112113
# Specifying repetitions directly in the commandline is ugly.
113114
# It ignores explicit settings and requires copying the repetition object from another task.
@@ -155,8 +156,7 @@
155156
#endregion Repetitions (ugly)
156157

157158
#region Setup Task Configuration
158-
if (-not $NoTask)
159-
{
159+
if (-not $NoTask) {
160160
$action = New-ScheduledTaskAction -Execute powershell.exe -Argument "-NoProfile -Command Invoke-MDDaemon"
161161
$triggers = @()
162162
$triggers += New-ScheduledTaskTrigger -AtStartup -RandomDelay "00:15:00"
@@ -173,21 +173,15 @@
173173
TaskName = 'MailDaemon'
174174
InputObject = $taskItem
175175
}
176-
if ($TaskUser)
177-
{
176+
if ($TaskUser) {
178177
$parametersRegister["User"] = $TaskUser.UserName
179178
$parametersRegister["Password"] = $TaskUser.GetNetworkCredential().Password
180179
}
181180
}
182181
#endregion Setup Task Configuration
183182

184183
#region Preparing Parameters
185-
$parameters = @{ }
186-
foreach ($key in $PSBoundParameters.Keys)
187-
{
188-
if ($key -notin 'PickupPath', 'SentPath', 'MailSentRetention', 'SmtpServer', 'SenderDefault', 'RecipientDefault') { continue }
189-
$parameters[$key] = $PSBoundParameters[$key]
190-
}
184+
$parameters = $PSBoundParameters | ConvertTo-PSFHashtable -Include 'PickupPath', 'SentPath', 'MailSentRetention', 'SmtpServer', 'SenderDefault', 'RecipientDefault', 'UseSSL'
191185

192186
$paramMainInstallCall = @{
193187
ArgumentList = $parameters
@@ -217,8 +211,7 @@
217211
#endregion The Main Setup Scriptblock
218212
}
219213

220-
process
221-
{
214+
process {
222215
#region Ensure Modules are installed
223216
$testResults = Test-Module -ComputerName $ComputerName -Credential $Credential -Module @{
224217
MailDaemon = $script:ModuleVersion
@@ -227,11 +220,9 @@
227220

228221
$failedTests = $testResults | Where-Object Success -EQ $false
229222

230-
if ($failedTests)
231-
{
223+
if ($failedTests) {
232224
$grouped = $failedTests | Group-Object Name
233-
foreach ($groupSet in $grouped)
234-
{
225+
foreach ($groupSet in $grouped) {
235226
Copy-Module -ModuleName (Get-Module $groupSet.Name).ModuleBase -ToComputer $groupSet.Group.ComputerName
236227
}
237228
}
@@ -242,13 +233,13 @@
242233
Invoke-PSFCommand @paramMainInstallCall
243234

244235
#region Securely store credentials
245-
if ($PSBoundParameters.ContainsKey('SenderCredential'))
246-
{
236+
if ($PSBoundParameters.ContainsKey('SenderCredential')) {
247237
$parametersSave = @{
248-
ComputerName = $ComputerName
249-
Credential = $SenderCredential
250-
Path = 'C:\ProgramData\PowerShell\MailDaemon\senderCredentials.clixml'
238+
ComputerName = $ComputerName
239+
TargetCredential = $SenderCredential
240+
Path = 'C:\ProgramData\PowerShell\MailDaemon\senderCredentials.clixml'
251241
}
242+
if ($Credential) { $parametersSave['Credential'] = $Credential }
252243
if ($TaskUser) { $parametersSave['AccessAccount'] = $TaskUser }
253244
Save-MDCredential @parametersSave
254245

@@ -260,10 +251,8 @@
260251
#endregion Securely store credentials
261252

262253
#region Setup Task
263-
if (-not $NoTask)
264-
{
265-
foreach ($computerObject in $ComputerName)
266-
{
254+
if (-not $NoTask) {
255+
foreach ($computerObject in $ComputerName) {
267256
if ($ComputerName.Type -like 'CimSession') { $parametersRegister["CimSession"] = $computerObject.InputObject }
268257
elseif (-not $ComputerName.IsLocalhost) { $parametersRegister["CimSession"] = $ComputerName }
269258

MailDaemon/functions/Invoke-MDDaemon.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
Encoding = ([System.Text.Encoding]::UTF8)
4949
ErrorAction = 'Stop'
5050
}
51+
if (Get-PSFConfigValue -FullName 'MailDaemon.Daemon.UseSSL' -Fallback $false) { $parameters['UseSSL'] = $true }
5152
if ($email.To) { $parameters["To"] = $email.To }
5253
else { $parameters["To"] = Get-PSFConfigValue -FullName 'MailDaemon.Daemon.RecipientDefault' }
5354
if ($email.From) { $parameters["From"] = $email.From }

MailDaemon/functions/Set-MDDaemon.ps1

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@
6666

6767
[string]
6868
$SenderCredentialPath,
69+
70+
[switch]
71+
$UseSSL,
6972

7073
[Parameter(ValueFromPipeline = $true)]
7174
[PSFComputer[]]
@@ -106,21 +109,15 @@
106109
'SenderDefault' { Set-PSFConfig -Module MailDaemon -Name 'Daemon.SenderDefault' -Value $Parameters[$key] }
107110
'SenderCredentialPath' { Set-PSFConfig -Module MailDaemon -Name 'Daemon.SenderCredentialPath' -Value $Parameters[$key] }
108111
'RecipientDefault' { Set-PSFConfig -Module MailDaemon -Name 'Daemon.RecipientDefault' -Value $Parameters[$key] }
112+
'UseSSL' { Set-PSFConfig -Module MailDaemon -Name 'Daemon.UseSSL' -Value $Parameters[$key].ToBool() }
109113
}
110114
}
111115

112116
Get-PSFConfig -Module MailDaemon -Name Daemon.* | Where-Object Unchanged -EQ $false | Register-PSFConfig -Scope SystemDefault
113117
}
114118
#endregion Configuration Script
115119

116-
#region Prepare parameters to pass through
117-
$parameters = @{ }
118-
foreach ($key in $PSBoundParameters.Keys)
119-
{
120-
if ($key -in 'ComputerName', 'Credential') { continue }
121-
$parameters[$key] = $PSBoundParameters[$key]
122-
}
123-
#endregion Prepare parameters to pass through
120+
$parameters = $PSBoundParameters | ConvertTo-PSFHashtable -Exclude ComputerName, Credential
124121
}
125122
process
126123
{

MailDaemon/internal/configurations/daemon.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ Set-PSFConfig -Module 'MailDaemon' -Name 'Daemon.MailSentRetention' -Value (New-
44
Set-PSFConfig -Module 'MailDaemon' -Name 'Daemon.SmtpServer' -Value "mail.$($env:USERDNSDOMAIN)" -Initialize -Validation 'string' -SimpleExport -Description "The mail server to use."
55
Set-PSFConfig -Module 'MailDaemon' -Name 'Daemon.SenderDefault' -Value "maildaemon@$($env:USERDNSDOMAIN)" -Initialize -Validation 'string' -SimpleExport -Description "The default sending email address."
66
Set-PSFConfig -Module 'MailDaemon' -Name 'Daemon.SenderCredentialPath' -Value '' -Initialize -Validation 'string' -SimpleExport -Description "The path to the credentials to use for authenticated mail sending."
7-
Set-PSFConfig -Module 'MailDaemon' -Name 'Daemon.RecipientDefault' -Value "support@$($env:USERDNSDOMAIN)" -Initialize -Validation 'string' -SimpleExport -Description "The default recipient to receive emails."
7+
Set-PSFConfig -Module 'MailDaemon' -Name 'Daemon.RecipientDefault' -Value "support@$($env:USERDNSDOMAIN)" -Initialize -Validation 'string' -SimpleExport -Description "The default recipient to receive emails."
8+
Set-PSFConfig -Module 'MailDaemon' -Name 'Daemon.UseSSL' -Value $false -Initialize -Validation 'bool' -SimpleExport -Description "Whether mails should be sent using SSL."

0 commit comments

Comments
 (0)