#!/usr/bin/env python3 # Before begin you need to change Gmail settings: # 1. Turn off 2-step verification # 2. Enable: Allow less secure apps from sender import Mail, Message mail = Mail("smtp.gmail.com", port=587, username="******", password="******", use_tls=True, use_ssl=False, debug_level=None) mail.fromaddr = ("Sender Name", "*****@*****.**") msg = Message("msg subject") msg.fromaddr = ("Sender Name", "*****@*****.**") msg.to = "*****@*****.**" msg.body = "this is a msg plain text body" msg.html = "<b>this is a msg text body</b>" msg.reply_to = "*****@*****.**" msg.charset = "utf-8" msg.extra_headers = {} msg.mail_options = [] msg.rcpt_options = [] # Send message mail.send(msg)
from sender import Mail, Message from .config import config email_conf = {} for setting in ('host', 'port', 'username', 'password', 'use_tls', 'use_ssl'): email_conf[setting] = config['email'][setting] MAIL = Mail(**email_conf) if 'from_pretty' in config['email']: MAIL.fromaddr = (config['email']['from_pretty'], config['email']['from_address']) else: MAIL.fromaddr = config['email']['from_address'] def send_jobs(jobs): "Send an email notifying of current jobs" msg = Message( config['email']['subject'].format(n=len(jobs)), to=config['email_address'], ) msg.body = "Found {n} potential jobs:\n\n" for idx, job in enumerate(jobs): idx += 1 msg.body += "{}. {}\n\n\n".format(idx, job.to_string()) MAIL.send(msg)