The server response was: 5.7.1 : Relay access denied

Welcome Forums General PowerShell Q&A The server response was: 5.7.1 : Relay access denied

Viewing 2 reply threads
  • Author
    Posts
    • #260253
      Participant
      Topics: 5
      Replies: 12
      Points: 70
      Rank: Member

      The server response was: 5.7.1 : Relay access denied

      Trying to send mail from Powershell to extern mailaccount but get Relay access denied.

      # ======================
      # Sending Email Section
      # ======================

      $strFrom = "mailfrom"
      $strPassword = "Psw"
      $strTo = "mailto"
      $strSubject = "Alert"
      $strSMTPServer = ""
      $strPort = 587

      $objEmailMessage = New-Object system.net.mail.mailmessage
      $objEmailMessage.From = ($strFrom)
      $objEmailMessage.To.Add($strTo)
      $objEmailMessage.Subject = $strSubject
      $objEmailMessage.IsBodyHTML = $true
      $objEmailMessage.Body = $mailbody

      $objSMTP.EnableSsl = $true
      $objSMTP.Credentials = New-Object System.Net.NetworkCredential($strFrom, $strPassword);
      $objSMTP = New-Object Net.Mail.SmtpClient($strSMTPServer, $strPort)
      $objSMTP.Send($objEmailMessage)

      Some idé whats wrong?

    • #260310
      Participant
      Topics: 25
      Replies: 197
      Points: 718
      Helping Hand
      Rank: Major Contributor

      first guess would be your credential object isn’t valid.
      or whatever creds you are passing is not allowed to send email through your SMTP server.

      in addition, look at send-mailmessage, built in powershell cmdlet to perform this action. and way easier to utilize.

    • #260373
      Participant
      Topics: 5
      Replies: 12
      Points: 70
      Rank: Member

      Absolutely I have rewritten the code for the following instead.
      I know that the security in this example is not the best, but I will solve it later.

      This works fine.

      • This reply was modified 3 weeks, 3 days ago by grokkit. Reason: code formatting - please read the guide
Viewing 2 reply threads
  • You must be logged in to reply to this topic.