Send-mailmessage

Welcome Forums General PowerShell Q&A Send-mailmessage

This topic contains 8 replies, has 4 voices, and was last updated by

 
Participant
2 years ago.

  • Author
    Posts
  • #54487

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 7
    Rank: Member

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

    • #54490

      Participant
      Points: 0
      Rank: Member

      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

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 7
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

      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

    Keymaster
    Points: 7
    Rank: Member

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

  • #54502

    Participant
    Points: 0
    Rank: Member
  • #54524

    Participant
    Points: 25
    Rank: Member

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

The topic ‘Send-mailmessage’ is closed to new replies.