Hi,
I’m trying to send, from windows 7, an e-mail using the following code:
$ computers1 = Get-WmiObject-Class Win32_ComputerSystem | out-file “C: \ ProgramData \ list1.txt”
$ computers2 = Get-WmiObject-Class Win32_Product | Select-Object Name -Property> C: \ ProgramData \ list2.txt
$ computers = Get-ChildItem C: \ ProgramData \ list1.txt, C: \ ProgramData \ list2.txt | Get-Content | out-file “C: \ ProgramData \ list.txt”
$EMAILTO = “xxxxx@gmail.com”
$Emailfrom = “me@mydomain.com”
$Subject = “Test”
$Body = “Test Body”
$SMTPServer = “smtp.gmail.com”
filenameAndPath filenameAndPath $ = $ = “C: \ ProgramData \ list.txt”
$SMTPMessage = New-Object System.Net.Mail.MailMessage ($emailfrom, $EMAILTO, $Subject, $Body)
$attachment = New-Object System.Net.Mail.Attachment ($filenameAndPath)
$SMTPMessage.Attachments.Add ($attachment)
$SMTPClient = New-Object Net.Mail.SmtpClient ($SmtpServer, 587)
SMTPClient.EnableSsl = $true
$SMTPClient.Credentials System.Net.NetworkCredential = New-Object (“xxxx”, “yyyyy”)
$SmtpClient.Send ($SMTPMessage)
but I get the following error:
Exception while calling “Send” with “1” argument / s: “The SMTP server requires a secure connection or the client was not authenticated. Unknown server response: 5.5.1 Authentication Required. Learn more at”
In line: car 17: 17
- $ SmtpClient.Send <<<< ($SMTPMessage)
- CategoryInfo: NotSpecified: ( , MethodInvocationException
- FullyQualifiedErrorId: DotNetMethodException
Why is that?