Link to home
Start Free TrialLog in
Avatar of jwc1972
jwc1972Flag for United Kingdom of Great Britain and Northern Ireland

asked on

SMTP send mail to users

HI,

I found this PowerShell on internet, when I run the PowerShell script I get the following error.  All my users are on a domain. do I need to pass something into the powershell?


send-mailmessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
At line:38 char:1
+ send-mailmessage -to $email -from noreply@domain.org -Subject "Password Reminder: ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
    + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage


import-module ActiveDirectory;
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
Get-ADUser -filter * -properties PasswordLastSet, PasswordExpired, PasswordNeverExpires, EmailAddress, GivenName | foreach {
    $today=get-date
    $UserName=$_.GivenName
    $Email=$_.EmailAddress
   if (!$_.PasswordExpired -and !$_.PasswordNeverExpires) {
        $ExpiryDate=$_.PasswordLastSet + $maxPasswordAgeTimeSpan
        $DaysLeft=($ExpiryDate-$today).days
        if ($DaysLeft -lt 5 -and $DaysLeft -gt 0){
        $WarnMsg = "
<p style='font-family:calibri'>Hi $UserName,</p>
<p style='font-family:calibri'>Your Windows login password will expire in 5 days, please press CTRL-ALT-DEL and change your password.  As a reminder, you will have to enter your new password into your DOMAIN connected mobile device if prompted.</p>
<p style='font-family:calibri'>Requirements for the password are as follows:</p>
<ul style='font-family:calibri'>
<li>Must not contain the user's account name or parts of the user's full name that exceed two consecutive characters</li>
<li>Must not be one of your last 7 passwords</li>
<li>Contain characters from three of the following four categories:</li>
<li>English uppercase characters (A through Z)</li>
<li>English lowercase characters (a through z)</li>
<li>Base 10 digits (0 through 9)</li>
<li>Non-alphabetic characters (for example, !, $, #, %)</li>
</ul>
<p style='font-family:calibri'>For any assistance, visit the <a href='http://ITHelpDesk'>IT Help Desk</a></p>
<p style='font-family:calibri'>-Technology Services</p>
"
ForEach ($email in $_.EmailAddress) {
send-mailmessage -to $email -from noreply@domain.org -Subject "Password Reminder: Your password will expire in $DaysLeft days" -body $WarnMsg  -smtpserver smtpserverIP -BodyAsHtml }

Write-Host "$email"
         }
    }
}
SOLUTION
Avatar of Satyendra Sharma
Satyendra Sharma
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jwc1972

ASKER

HI,

I'm running the script from my local PC, with admin rights
I have add the Ip of the exchange server

$cred = get-credential
then insert this into sendmail
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jwc1972

ASKER

HI,

nope no luck, everything looks right, I'm wondering if something on the exchange server is blocking this

thank you for trying
Can you look at the protocol log on the receive connector on the exchange server?
If you have a dedicated relay connector can you try using that?
Avatar of jwc1972

ASKER

ok cheers,

our exchange server is hosted by another company, I will check in the morning
I would've waited till you had verified a solution before closing the question.