import smtplib import constants from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText username = constants.EMAIL_USERNAME password = constants.EMAIL_PASSWORD def handle(link_to_apartment): from_addr = username to_addr = "alex@pwnh.io" server = smtplib.SMTP('smtp.gmail.com:587') server.starttls() server.login(username, password) text = link_to_apartment text = MIMEText(text.encode('utf-8'), 'html', 'utf-8') msg = MIMEMultipart('alternative') msg['Subject'] = 'Fundet ny lejlighed' msg['From'] = from_addr msg['To'] = to_addr msg.attach(text) server.sendmail(from_addr, to_addr, msg.as_string()) server.quit()