Send-mailmessage

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.”

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

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

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.

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 ;).

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

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

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