jwc1972
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.SmtpClien t:SmtpClie nt) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.Po werShell.C ommands.Se ndMailMess age
import-module ActiveDirectory;
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswo rdPolicy). MaxPasswor dAge
Get-ADUser -filter * -properties PasswordLastSet, PasswordExpired, PasswordNeverExpires, EmailAddress, GivenName | foreach {
$today=get-date
$UserName=$_.GivenName
$Email=$_.EmailAddress
if (!$_.PasswordExpired -and !$_.PasswordNeverExpires) {
$ExpiryDate=$_.PasswordLas tSet + $maxPasswordAgeTimeSpan
$DaysLeft=($ExpiryDate-$to day).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 '>Requirem ents 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 '>-Technol ogy 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"
}
}
}
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.SmtpClien
+ FullyQualifiedErrorId : SmtpException,Microsoft.Po
import-module ActiveDirectory;
$maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswo
Get-ADUser -filter * -properties PasswordLastSet, PasswordExpired, PasswordNeverExpires, EmailAddress, GivenName | foreach {
$today=get-date
$UserName=$_.GivenName
$Email=$_.EmailAddress
if (!$_.PasswordExpired -and !$_.PasswordNeverExpires) {
$ExpiryDate=$_.PasswordLas
$DaysLeft=($ExpiryDate-$to
if ($DaysLeft -lt 5 -and $DaysLeft -gt 0){
$WarnMsg = "
<p style='font-family:calibri
<p style='font-family:calibri
<p style='font-family:calibri
<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
<p style='font-family:calibri
"
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HI,
nope no luck, everything looks right, I'm wondering if something on the exchange server is blocking this
thank you for trying
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?
If you have a dedicated relay connector can you try using that?
ASKER
ok cheers,
our exchange server is hosted by another company, I will check in the morning
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.
ASKER
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