Allow for unauthenticated SMTP. (#81)
* Allow for unauthenticated SMTP, fixes #66
This commit is contained in:
10
backup.ps1
10
backup.ps1
@@ -302,8 +302,12 @@ function Send-Email {
|
||||
$Action = "Backup"
|
||||
}
|
||||
|
||||
$password = ConvertTo-SecureString $ResticEmailPassword -AsPlainText -Force
|
||||
$credentials = New-Object System.Management.Automation.PSCredential ($ResticEmailUsername, $password)
|
||||
if ([String]::IsNullOrEmpty($ResticEmailPassword)) {
|
||||
$ResticEmailCredentials = @{}
|
||||
} else {
|
||||
$password = ConvertTo-SecureString $ResticEmailPassword -AsPlainText -Force
|
||||
$ResticEmailCredentials = @{Credential = New-Object System.Management.Automation.PSCredential ($ResticEmailUsername, $password)}
|
||||
}
|
||||
|
||||
$status = "SUCCESS"
|
||||
$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
|
||||
$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 $?) {
|
||||
"[[Email]] Sending email completed with errors" | Tee-Object -Append $temp_error_log | Out-File -Append $SuccessLog
|
||||
|
||||
@@ -13,5 +13,5 @@ $PSEmailServer='<SMTP SERVER>'
|
||||
$ResticEmailConfig=@{UseSsl=$true; Port="587"}
|
||||
$ResticEmailTo='<DESTINATION EMAIL ADDRESS>'
|
||||
$ResticEmailFrom='<FROM EMAIL ADDRESS>'
|
||||
$ResticEmailUsername='<EMAIL LOGIN USERNAME>'
|
||||
$ResticEmailPassword='<EMAIL PASSWORD>'
|
||||
$ResticEmailUsername='<EMAIL LOGIN USERNAME OR EMPTY FOR NO USERNAME>'
|
||||
$ResticEmailPassword='<EMAIL PASSWORD OR EMPTY FOR NO PASSWORD>'
|
||||
|
||||
Reference in New Issue
Block a user