import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart from typing import Text, Union, Iterable def mailing_main(subject:Text, body:Text, to_address:Union[Text, Iterable[Text]]): """Sends the email with the given subject and body to the given address (accepts also list of addresses).""" # Mailing server configuration smtp_server = 'smtp.gmail.com.' smtp_port = 587 sender_email = 'bainhackathon@gmail.com' sender_password = 'onyghfffdbmurjdf' # This creates the actual email message msg = MIMEMultipart() msg['From'] = sender_email msg['To'] = to_address msg['Subject'] = subject msg.attach(MIMEText(body, 'plain')) # Connects to SMTP server and then sends the actual email try: server = smtplib.SMTP(smtp_server, smtp_port) server.starttls() server.login(sender_email, sender_password) server.sendmail(sender_email, to_address, msg.as_string()) server.quit() print("Email sent successfully!") except Exception as e: print("Error sending email:", e)