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

Welcome Forums General PowerShell Q&A Powershell scripts not working in a cloud VM, but does on main computer

Viewing 3 reply threads
  • Author
    Posts
    • #212100
      Participant
      Topics: 1
      Replies: 1
      Points: 16
      Rank: Member

      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 )
      • This topic was modified 2 months, 1 week ago by Feint40.
    • #212124
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

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

    • #212130
      Participant
      Topics: 1
      Replies: 1
      Points: 16
      Rank: Member

      Send-MailMessage

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

    • #212145
      Participant
      Topics: 4
      Replies: 2247
      Points: 5,484
      Helping Hand
      Rank: Community MVP

      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. 😉 If the code works in general it might be something else.

Viewing 3 reply threads
  • You must be logged in to reply to this topic.