This topic contains 3 replies, has 4 voices, and was last updated by
March 14, 2019 at 12:04 pm #144378ParticipantPoints: -7Rank: Member
$SMTPServer = "*******.*****.***"$SMTPServerPort = "587"
$Username = "*****@******.***"
$Password = "******"
$smtp.EnableSsl = $true
$to = "*******@*****.***"
$subject = "Results for AD Report LAST LOGON"
$body = "Script version 1.0 by Maarten Mol"
$attachment = "C:\prova.txt"
$message = New-Object System.Net.Mail.MailMessage
$message.subject = $subject
$message.body = $body
$message.from = $username
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
Exception during the "Send" argument with argument "4": "The SMTP server requires a secure connection or the client was not authenticated. Server response: 5.7.1 The client was not authenticated"In C:\Users\Roberto.Bugatti\Desktop\invioemail\mailsender.ps1:27 car:1 + $smtp.send($to,$Username,$body,$attachment)+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo : NotSpecified: (:) , MethodInvocationException+ FullyQualifiedErrorId : SmtpException
March 14, 2019 at 12:46 pm #144710ParticipantPoints: 181Rank: Participant
It would appear that you're not successfully authenticating with your smtp server, most likely requires SSL or something similar.
Also, why use the .net providers here, when Powershell has a native cmdlet send-mailmessage.
March 14, 2019 at 1:40 pm #144723ParticipantPoints: 638Rank: Major Contributor
I see port 587, I think Office 365, but regardless here is an example of using Send-MailMessage:
March 14, 2019 at 3:26 pm #144758ParticipantPoints: 140Rank: Participant
Not the best example but it works$login = "Login name" $password = "Password" | Convertto-SecureString -AsPlainText -Force $credentials = New-Object System.Management.Automation.Pscredential -Argumentlist $login,$passwordSend-MailMessage -SmtpServer smtp.office365.com -from "From@email.nl" -credential $credentials -to "To@email.nl" -subject "Subject" -Body "Body" -UseSsl
You must be logged in to reply to this topic.