Allow for unauthenticated SMTP. (#81)

* Allow for unauthenticated SMTP, fixes #66
This commit is contained in:
SeeJayEmm
2024-11-11 02:26:31 -05:00
committed by GitHub
parent 5a660ea5d6
commit aad279210a
2 changed files with 9 additions and 5 deletions

View File

@@ -302,8 +302,12 @@ function Send-Email {
$Action = "Backup" $Action = "Backup"
} }
$password = ConvertTo-SecureString $ResticEmailPassword -AsPlainText -Force if ([String]::IsNullOrEmpty($ResticEmailPassword)) {
$credentials = New-Object System.Management.Automation.PSCredential ($ResticEmailUsername, $password) $ResticEmailCredentials = @{}
} else {
$password = ConvertTo-SecureString $ResticEmailPassword -AsPlainText -Force
$ResticEmailCredentials = @{Credential = New-Object System.Management.Automation.PSCredential ($ResticEmailUsername, $password)}
}
$status = "SUCCESS" $status = "SUCCESS"
$past_failure = $false $past_failure = $false
@@ -334,7 +338,7 @@ function Send-Email {
# create a temporary error log to log errors; can't write to the same file that Send-MailMessage is reading # create a temporary error log to log errors; can't write to the same file that Send-MailMessage is reading
$temp_error_log = $ErrorLog + "_temp" $temp_error_log = $ErrorLog + "_temp"
Send-MailMessage @ResticEmailConfig -From $ResticEmailFrom -To $ResticEmailTo -Credential $credentials -Subject $subject -Body $body @attachments 3>&1 2>> $temp_error_log Send-MailMessage @ResticEmailConfig -From $ResticEmailFrom -To $ResticEmailTo @ResticEmailCredentials -Subject $subject -Body $body @attachments 3>&1 2>> $temp_error_log
if(-not $?) { if(-not $?) {
"[[Email]] Sending email completed with errors" | Tee-Object -Append $temp_error_log | Out-File -Append $SuccessLog "[[Email]] Sending email completed with errors" | Tee-Object -Append $temp_error_log | Out-File -Append $SuccessLog

View File

@@ -13,5 +13,5 @@ $PSEmailServer='<SMTP SERVER>'
$ResticEmailConfig=@{UseSsl=$true; Port="587"} $ResticEmailConfig=@{UseSsl=$true; Port="587"}
$ResticEmailTo='<DESTINATION EMAIL ADDRESS>' $ResticEmailTo='<DESTINATION EMAIL ADDRESS>'
$ResticEmailFrom='<FROM EMAIL ADDRESS>' $ResticEmailFrom='<FROM EMAIL ADDRESS>'
$ResticEmailUsername='<EMAIL LOGIN USERNAME>' $ResticEmailUsername='<EMAIL LOGIN USERNAME OR EMPTY FOR NO USERNAME>'
$ResticEmailPassword='<EMAIL PASSWORD>' $ResticEmailPassword='<EMAIL PASSWORD OR EMPTY FOR NO PASSWORD>'