diff --git a/auditemail.py b/auditemail.py new file mode 100644 index 0000000..ea98425 --- /dev/null +++ b/auditemail.py @@ -0,0 +1,60 @@ +import smtplib +import ssl +import os + +# Define the Windows file path to the audit log (use \\ for any directory slashes): +audit_log_path = "" + +# Email address settings: +sender_email = "" +receiver_email = "" + +# SMTP server settings: +smtp_server = "" +smtp_username = "" +smtp_password = "" +smtp_port = + + +def main(): + + # Create a secure SSL context + context = ssl.create_default_context() + + # Opens and reads the audit log text file + if os.path.exists(audit_log_path) == True: + + try: + with open(audit_log_path, "r") as audit_log: + timestamp = audit_log.readline() + audit_content = audit_log.read() + + message = """\ +From: {} +To: {} +Subject: {} +{}""".format( + sender_email, receiver_email, timestamp, audit_content + ) + except Exception as e: + print(e) + else: + message = """\ +From: {} +To: {} +Subject: Audit Failed: Audit Log File Does Not Exist +Audit log was not found at {}. +Ensure that you have configured the correct file path and that the file exists.""".format( + sender_email, receiver_email, audit_log_path + ) + + with smtplib.SMTP_SSL(smtp_server, smtp_port, context=context) as server: + try: + server.login(smtp_username, smtp_password) + server.sendmail(sender_email, receiver_email, message) + except Exception as e: + print(e) + + +if __name__ == "__main__": + main() \ No newline at end of file