Import Smtplib
Import Smtplib
Args:
sender_email: The sender's email address.
sender_password: The sender's email password.
receiver_email: The recipient's email address.
student_name: The student's full name.
student_info: The student's information (can include HTML).
attachment_path: The path to the attachment file.
"""
try:
msg = MIMEMultipart()
msg['From'] = sender_email
msg['To'] = receiver_email
msg['Subject'] = f'{student_id} - {student_name}'
# Attach file
if os.path.exists(attachment_path):
with open(attachment_path, "rb") as attachment:
part = MIMEBase("application", "octet-stream")
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header(
"Content-Disposition",
f"attachment; filename= {os.path.basename(attachment_path)}",
)
msg.attach(part)
else:
print(f"Error: Attachment file not found at {attachment_path}")
return
except Exception as e:
print(f"Error sending email: {e}")