import smtplib from email.mime.text import MIMEText def send_email(): from_address = 'from@domain.com' to_addresses = [subscriber['email'] for subscriber in subscribers] print "Sending emails to ", ", ".join(to_addresses) msg = MIMEText(EMAIL_BODY, 'html') msg["Subject"] = "Some Subject" msg["From"] = from_address msg["To"] = ", ".join(to_addresses) try: # set up the SMTP server server = smtplib.SMTP(host='smtp.gmail.com', port=587) server.ehlo() server.starttls() #s.set_debuglevel(1) server.login(EMAIL_ADDRESS, EMAIL_PASSWORD) server.sendmail(from_address, to_addresses, msg.as_string()) # Terminate the SMTP session and close the connection server.quit() print "Mail Sent Successfully." except: print "Sending mail failed..!"