Powershell Send-MailMessage 오류

Powershell Send-MailMessage 오류

Send-MailMessage를 Office365 이메일과 함께 사용할 수 없어 이제 Gmail로 시도했지만 여전히 작동하지 않습니다.

오류 발생:Send-MailMessage: SMTP 서버에 보안 연결이 필요하거나 클라이언트가 인증되지 않았습니다. 서버 응답은 5.5.1 인증 필요입니다.

유사한 메일 보내기 오류를 많이 찾아보고 여러 가지 제안을 시도했습니다.

  • Gmail 보안 설정에서 '보안 수준이 낮은 앱 사용'을 켰습니다.
  • useSSL 제거를 시도했습니다.
  • Gmail 주소와 비밀번호를 다시 확인하세요.

Powershell을 처음 사용하는 사람이 나에게 올바른 방향을 알려줄 수 있습니까? 아래 코드:

 $From = "[email protected]"
 $To = "[email protected]"
 $Subject = "Here's the Email Subject"
 $Body = "This is what I want to say"
 $SMTPServer = "smtp.gmail.com"
 $SMTPPort = "587"
 Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential (Get-Credential)

답변1

객체를 정의하고 Get-Credential객체의 반환 값을 할당해야 한다고 생각합니다.

이렇게:

$cred = Get-Credential
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential $cred

출처/추가 정보:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/get-credential?view=powershell-6

관련 정보