Issue sending SMTP mail from VMWorkstation using Powershell
I have the following script that I use to send an email when running a
PowerShell program, and it works wonderfully well, usually:
$msg = New-Object System.Net.Mail.MailMessage
$msg.From = $from
$msg.To.Add($to)
$msg.Subject = $subject
$msg.Body = $html
$msg.IsBodyHtml = $true
$smtp = New-Object System.Net.Mail.SmtpClient($server)
$smtp.Credentials =
[System.Net.CredentialCache]::DefaultNetworkCredentials
try
{
$smtp.Send($msg)
Write-Host "Email sent to $to without error"
}
catch
{
$retryCount++
Write-Warning "Email failed to send. $_.Exception.Message"
}
The issue is that I have since began to use this script in a VMWorkstation
machine that I just set up, and I am unable to send the email at this
point. Here is the error I'm getting:
WARNING: Email failed to send. 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.1 Client was not
authent
icated".Exception.Message
I believe I am getting this error because I use:
$smtp.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Is this the case? If so, is there a way I can pull my credential from my
VM? I am using a bridged network, so I don't know why I couldn't access
them with that call. I have also changed all the domain permissions to my
corporate network.
Any insight would be helpful.
No comments:
Post a Comment