import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart def send_email(sender, receiver, password, good_fit_jobs): print("preparing message") html_body = """

My Job Alert

{count} jobs have been found that match your profile:

""" message = MIMEText(html_body, "html") message["Subject"] = f"MY JOB ALERT: {len(good_fit_jobs)} jobs has been found" message["From"] = sender message["To"] = receiver print(f"Sending email with {len(good_fit_jobs)} jobs") with smtplib.SMTP("smtp.gmail.com", timeout=60, port=587) as connection: connection.starttls() connection.login(user=sender, password=password) connection.sendmail( from_addr=sender, to_addrs=receiver, msg=message.as_string(), ) connection.close()