Jul-01-2024, 03:51 PM
wow got it all to work, heres the end result
import smtplib from email.mime.text import MIMEText import subprocess un = "robert.wild" dom = "dc01.robo84.net" cnp = "Password01!" une = subprocess.run(f'powershell.exe $cred = Import-CliXml -Path C:\\python\\cred.xml; Get-aduser -credential $cred -server {dom} -identity {un} -properties * | select-object -expandproperty mail', capture_output=True, text=True, shell=False) smtp_server = '172.17.1.5' smtp_user = '[email protected]' smtp_connection = smtplib.SMTP(smtp_server) email_body = f'hello {un} your new password is {cnp} for {dom}' email_message = MIMEText(email_body) email_message['Subject'] = 'password change' email_message['From'] = '[email protected]' smtp_connection.sendmail(smtp_user, {une.stdout}, email_message.as_string()) smtp_connection.quit()