-1

I tried the following

send-mailmessage -subject "hi" -to "abc@abc.com" -from "abc@abc.com" -UseSsl -SmtpServer "smtp.office365.com" -port 25 -Credential (Get-Credential)

I even tried with different ports but it is throwing the below exception

send-mailmessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [XXXXXXXXXXX.YYYYYY.PROD.OUTLOOK.COM]

then I even tried System.Net.Mail.SmtpClient:SmtpClient method but even this is throwing the same error

jayasree
  • 1
  • 3

1 Answers1

0

Try it like this :


$emailSmtpServer = "mail"
$emailSmtpServerPort = "587"
$emailSmtpUser = "user"
$emailSmtpPass = "P@ssw0rd"
 
$emailFrom = "from"
$emailTo = "to"
$emailcc="CC"
 
$emailMessage = New-Object System.Net.Mail.MailMessage( $emailFrom , $emailTo )
$emailMessage.cc.add($emailcc)
$emailMessage.Subject = "subject" 
#$emailMessage.IsBodyHtml = $true #true or false depends
$emailMessage.Body = "body"
 
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.EnableSsl = $False
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass );
$SMTPClient.Send( $emailMessage )

  • 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.7.57 SMTP; Client was not authenticated to send anonymous mail during MAIL FROM [XXXXXXXX.YYYYYY.PROD.OUTLOOK.COM]" At line:19 char:1 + $SMTPClient.Send( $emailMessage ) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SmtpException this is what i get while using the above method you suggested. – jayasree Jul 02 '20 at 07:43