예제 #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)
         ],
     )
예제 #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)
예제 #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)
                                ])
예제 #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)
예제 #5
0
파일: api.py 프로젝트: lxzxl/mailthon
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),
        ],
    )
예제 #6
0
파일: Testes.py 프로젝트: ThiDevs/Projects
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! :)")
예제 #7
0
    def test_no_force(self, conn):
        tls = TLS()
        tls(conn)

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

        assert tls_started(conn)
예제 #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)
예제 #10
0
파일: e-mail.py 프로젝트: ThiDevs/Projects
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! :)")