Powershell scripts not working in a cloud VM, but does on main computer

Hello everyone,

I have a mail sending powershell script that works when i run it on my host computer.

But when i run it on my windows server VM its not working, i get an error saying : 5.7.0 Authentication Required

its weird that its working on my main pc but not in the cloud windows server VM

anyone has an idea why its not working in a VM?

$emailSmtpServer = "smtp.gmail.com"
$emailSmtpServerPort = "587"
$emailSmtpUser = "xxxxx@gmail.com"
$emailSmtpPass = "xxxx"

$emailFrom = "xxxx@gmail.com"
$emailTo = "xxxx@gmail.com"
$emailcc="xxxx@gmail.com"
$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.cc.add($emailcc)
$emailMessage.Subject = "Service Monitor Status"
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = "ii"
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $true #True in most cases check
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
$SMTPClient.Send( $emailMessage )

Is there a special reason why you’re not using Send-MailMessage to send mail messages?

I’ve changed the script to use Send-MailMessage, and it works, but i doesnt work on my VM

So you will have to figure out what’s different when sending from your VM. :wink: If the code works in general it might be something else.