def init_mailthon(self): self.postman = Postman( host=self.server, port=self.port, middlewares=[ TLS(force=True), Auth(username=self.username, password=self.password) ], )
def send_email(config, user_email, subject, content): envelope = email(sender=SENDER, receivers=[user_email], subject=subject, content=content) postman = Postman(host=config['host'], port=int(config['port']), middlewares=[TLS(force=True), Auth(username=config['username'], password=config['password'])]) postman.send(envelope)
def __init__(self): """check email-service parameters from config.py""" if self.host == "": self.error_message = "Email Error: host is empty" elif self.username == "": self.error_message = "Email Error: username is empty" elif self.password == "": self.error_message = "Email Error: password is empty" else: self.available = True # initial postman self.postman = Postman(host=self.host, port=self.port, middlewares=[ TLS(force=True), Auth(username=self.username, password=self.password) ])
def send_email(config, user_email, subject, content): envelope = email( sender=SENDER, receivers=[user_email], subject=subject, content=content ) postman = Postman(host=config['mail.host'], port=int(config['mail.port']), middlewares=[TLS(force=True), Auth(username=config['mail.username'], password=config['mail.password'])]) try: response = postman.send(envelope) if response.ok: logger.info("Successfully send email to %s" % user_email) else: logger.error("Failed to send email to %s" % user_email) except Exception, e: logger.error("Exception occured when send email to %s" % e)
def postman(host, port=587, auth=(None, None), force_tls=False, options=None): """ Creates a Postman object with TLS and Auth middleware. TLS is placed before authentication because usually authentication happens and is accepted only after TLS is enabled. :param auth: Tuple of (username, password) to be used to ``login`` to the server. :param force_tls: Whether TLS should be forced. :param options: Dictionary of keyword arguments to be used when the SMTP class is called. """ return Postman( host=host, port=port, options=options, middlewares=[ TLS(force=force_tls), Auth(*auth), ], )
def email(): postman = Postman( host='SOLLOES-VM02.SOLLOBRASIL.NET', port=587, middlewares=[ TLS(force=True), Auth(username='******', password='******') ], ) envelope = email( sender='sender <*****@*****.**>', receivers=['*****@*****.**'], subject='Manutenção/Suporte', content='', ) response = postman.send(envelope) print(response.message) print(response.status_code) if response.ok: print("OK! :)")
def test_no_force(self, conn): tls = TLS() tls(conn) assert not tls_started(conn)
def test_force(self, conn): tls = TLS(force=True) tls(conn) assert tls_started(conn)
def test_no_force(self, conn): tls = TLS() tls(conn) assert conn.mock_calls[0] == call.has_extn('STARTTLS') assert tls_started(conn)
from mailthon.postman import Postman from mailthon.middleware import TLS, Auth from mailthon import email while (True): postman = Postman( host='smtp-mail.outlook.com', port=587, middlewares=[ TLS(force=True), Auth(username='******', password='') ], ) envelope = email( sender='sender <*****@*****.**>', receivers=['*****@*****.**'], subject='Manutenção/Suporte', content='Hi', ) response = postman.send(envelope) print(response.message) print(response.status_code) if response.ok: print("OK! :)")