Send-mailmessage

This topic contains 8 replies, has 4 voices, and was last updated by Profile photo of Rob Simmers Rob Simmers 2 months, 2 weeks ago.

  • Author
    Posts
  • #54487
    Profile photo of Rohan Bisht
    Rohan Bisht
    Participant

    Hi,

    I am trying to send mail using the send-mailmessage commandlet, however I am getting the below error. I am using powershell on windows 10

    "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.5.1 Authentication Required."

  • #54488
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Your mail server requires an authenticated connection, and you did not provide credentials.

    • #54490
      Profile photo of Rohan Bisht
      Rohan Bisht
      Participant

      Thanks for the quick response!

      This is what I am using:
      $b=get-credential -credential "abc@gmail.com"
      Send-MailMessage -to "xyz@gmail.com" -From "abc@gmail.com" -Subject "test" -body "test mail" -SmtpServer "smtp.gmail.com" -Port 587 -Credential $b

      Below is the error I am getting:
      Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server
      response was: 5.7.0 Must issue a STARTTLS command first. 1sm1439957ioz.34 – gsmtp

  • #54491
    Profile photo of Rohan Bisht
    Rohan Bisht
    Participant

    And if I use -usessl then the error changes a bit –

    Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server
    response was: 5.5.1 Authentication Required.

  • #54493
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Contact your mail server admin. Find out how they've got the server set up for incoming SMTP connections. That's where your problem lies. It's possible to set servers up in a way that Send-MailMessage can't work – it's a fairly dumbed-down cmdlet. You might have to manually code this up using the underlying .NET Framework classes. But without knowing what the server requires, there's no way to tell you what to code ;).

    • #54495
      Profile photo of Rohan Bisht
      Rohan Bisht
      Participant

      Okay, but I am using the gmail smtp server here. How/where can I get the information on how the gmail server is setup for incoming SMTP connections? By the way, I wanted to use my company mailbox for sending mails using powershell which is on office 365, not sure where to contact for incoming SMTP connections setup

  • #54496
    Profile photo of Don Jones
    Don Jones
    Keymaster

    You would need to contact either Google or Microsoft support for that, and explain what you're trying to do.

  • #54502
    Profile photo of Curtis Smith
    Curtis Smith
    Participant
  • #54524
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Just a note. The gmail account cannot have dual authentication enabled.

You must be logged in to reply to this topic.