SMTPClient Failure During Send Concerning Arguments
<p>I am trying to setup an email PowerShell script that will let me send an email when the task scheduler runs the script. The problem i am getting is:</p>
<blockquote>
<p>Exception calling &quot;Send&quot; with &quot;1&quot; argument(s): &quot;The remote certificate is invalid according to the validation procedure.&quot;</p>
</blockquote>
<p>I am running the following code:</p>
<pre><code>$SMTPClient = New-Object Net.Mail.SmtpClient(&quot;SMTP&quot;, PORT)
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(&quot;username&quot;, &quot;password&quot;)
$MailMessage = (New-Object system.net.mail.mailmessage)
$MailMessage.from = (&quot;FROM&quot;)
$MailMessage.To.Add(&quot;TO&quot;)
$MailMessage.Subject = (&quot;Subject&quot;)
$MailMessage.Body = (&quot;Body&quot;)
$Smtpclient.EnableSsl = ($true)
$SmtpClient.Timeout = (300000)
$SmtpClient.Send($MailMessage)
Write-Output &quot;Message sent&quot;;
</code></pre>
<p>It gives me the error as specified above. Why?</p>