import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart # Function to send an email notification def send_email(sender_email, password, to_email, subject): # Create a MIMEMultipart email object to support multiple parts (e.g., HTML content) message = MIMEMultipart('alternative') message['Subject'] = subject # Set the email subject message['From'] = sender_email # Set the sender's email address message['To'] = to_email # Set the recipient's email address message['CC'] = "czhang@wtamu.edu" # CC to faculty advisor # HTML content for the email body html_content = """ Welcome to BuffTeks!
Welcome to BuffTeks!

Dear New Member,

Thank you for your interest in the BuffTeks student organization! We're excited to have you with us. To further enrich your experience and connect with fellow members, we have set up a Discord server for BuffTeks. This platform will allow you to engage in discussions, seek help, share insights, and participate in various club activities.

Please join the BuffTeks Discord via the invitation link: https://discord.gg/dU8vKfAjxv

Once you're in, take a moment to review our server rules and introduce yourself in the "Introductions" channel. If you have any questions, don't hesitate to reach out.

We look forward to seeing you there!

Sincerely,

BuffTeks Faculty Advisor

Cheng (Carl) Zhang, Ph.D.
Paul Engler Professor of Business Innovation
Assistant Professor of Computer Information Systems
Paul and Virginia Engler College of Business
West Texas A&M University, Canyon, TX
Email: czhang@wtamu.edu

""" # Convert the HTML content to a MIMEText object for HTML format html_part = MIMEText(html_content, 'html') # Attach the HTML part to the MIMEMultipart message message.attach(html_part) try: # Connect to the SMTP server and send the email with smtplib.SMTP('mail.privateemail.com', 587) as server: server.starttls() # Enable TLS encryption for secure connection server.login(sender_email, password) # Log in with the sender's email and password server.send_message(message) # Send the email message print("Email sent successfully!") except Exception as e: # Catch and display any exceptions that occur during the sending process print(f"Failed to send email: {str(e)}")