Thanks for the time and looking at this.
The error I'm getting:
Exception calling "Send" with "1" argument(s): "The SMTP server requires a secure connection or the client was not authenticated.
The server response was: 5.7.57 Client not authenticated to send mail. Error: 535 5.7.139
Authentication unsuccessful, the user credentials were incorrect. [CH2PR10CA0024.namprd10.prod.outlook.com]"
At C:\Batch\SendLog.ps1:41 char:1
- $SMTPClient.Send($SMTPMessage)
The thing is the creds are correct!
Here's the code that's in use now..(it's called after a robocopy is complete and is designed to send the logs to me)
$User = "someuser@harsh.com .com"
$File = "c:\batch\MyPassword.txt" (the MyPassword.txt was updated to be sure)
$dirPath ="C:\Logs"
$sendThisFile = ""
$cred=New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, (Get-Content $File | ConvertTo-SecureString)
$EmailTo = "someuser@harsh.com .com"
$EmailFrom = "someuser@harsh.com .com"
$SMTPServer = "smtp.outlook.com"
$ChkFile = $dirPath + "\dbackup.txt"
$fileExist = Test-Path $ChkFile
if ($fileExist -eq $True) {
$sendThisFile = $ChkFile;
$Subject = "Daily Backup Notification" ;
$Body = "Here are last night backup results. Review attachment." }
elseif
(
$sendThisFile = $dirPath + "\wbackup.txt"
)
{
$Subject = "Weekly Backup Notification";
$Body = "Here is the Weekly Full Backup Notification. Review Attachment."
}
else
{
$sendThisFile = $dirPath + "\error.txt";
$Subject = "Error on Backup"
$Body = "An error has occurred with last nights backup. Backup drive was not available. Review attachment for details."
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 // added as a test
$SMTPMessage = New-Object System.Net.Mail.MailMessage($EmailFrom,$EmailTo,$Subject,$Body)
$attachment = New-Object System.Net.Mail.Attachment($sendThisFile)
$SMTPMessage.Attachments.Add($attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($cred.UserName, $cred.Password);
$SMTPClient.Send($SMTPMessage)
Exit
But it's also a few other devices..like my epson workforce scanner,, scan to email function. used to work.. now.. nope.,