Beispiel #1
0
 def init_mailthon(self):
     self.postman = Postman(
         host=self.server,
         port=self.port,
         middlewares=[
             TLS(force=True),
             Auth(username=self.username, password=self.password)
         ],
     )
Beispiel #2
0
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)
Beispiel #3
0
 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)
                                ])
Beispiel #4
0
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)
Beispiel #5
0
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),
        ],
    )
Beispiel #6
0
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! :)")
Beispiel #7
0
    def test_no_force(self, conn):
        tls = TLS()
        tls(conn)

        assert not tls_started(conn)
Beispiel #8
0
    def test_force(self, conn):
        tls = TLS(force=True)
        tls(conn)

        assert tls_started(conn)
Beispiel #9
0
    def test_no_force(self, conn):
        tls = TLS()
        tls(conn)

        assert conn.mock_calls[0] == call.has_extn('STARTTLS')
        assert tls_started(conn)
Beispiel #10
0
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! :)")