Example #1
0
 def test_failed_login(self):
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     mail.settings.login = '******'
     self.assertFalse(mail.send(to=['*****@*****.**'],
                                subject='hello',
                                # If reply_to is omitted, then mail.settings.sender is used
                                reply_to='*****@*****.**',
                                message='world'))
Example #2
0
 def test_tls(self):
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     mail.settings.tls = True
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               subject='hello',
                               # If reply_to is omitted, then mail.settings.sender is used
                               reply_to='*****@*****.**',
                               message='world'))
     TestMail.DummySMTP.inbox.pop()
Example #3
0
 def test_html(self):
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               subject='hello',
                               # If reply_to is omitted, then mail.settings.sender is used
                               reply_to='*****@*****.**',
                               message='<html><head></head><body></body></html>'))
     message = TestMail.DummySMTP.inbox.pop()
     self.assertTrue('Content-Type: text/html' in message.payload)
 def test_alternative(self):
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               message=('Text only', '<html><pre>HTML Only</pre></html>')))
     message = TestMail.DummySMTP.inbox.pop()
     self.assertTrue(message.parsed_payload.is_multipart())
     self.assertTrue(message.parsed_payload.get_content_type() == 'multipart/alternative')
     parts = message.parsed_payload.get_payload()
     self.assertTrue('Text only' in parts[0].as_string())
     self.assertTrue('<html><pre>HTML Only</pre></html>' in parts[1].as_string())
Example #5
0
 def test_login(self):
     TestMail.DummySMTP.users['username'] = '******'
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     mail.settings.login = '******'
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               subject='hello',
                               # If reply_to is omitted, then mail.settings.sender is used
                               reply_to='*****@*****.**',
                               message='world'))
     del TestMail.DummySMTP.users['username']
     TestMail.DummySMTP.inbox.pop()
Example #6
0
 def test_hello_world(self):
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               subject='hello',
                               # If reply_to is omitted, then mail.settings.sender is used
                               reply_to='*****@*****.**',
                               message='world'))
     message = TestMail.DummySMTP.inbox.pop()
     self.assertEqual(message.sender, mail.settings.sender)
     self.assertEqual(message.to, ['*****@*****.**'])
     header = "To: [email protected]\nReply-To: [email protected]\nSubject: hello\n"
     self.assertTrue(header in message.payload)
     self.assertTrue(message.payload.endswith('world'))
Example #7
0
 def test_attachment(self):
     module_file = os.path.abspath(__file__)
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               subject='hello',
                               message='world',
                               attachments=Mail.Attachment(module_file)))
     message = TestMail.DummySMTP.inbox.pop()
     import email
     parsed_msg = email.message_from_string(message.payload)
     attachment = parsed_msg.get_payload(1).get_payload(decode=True)
     with open(module_file, 'rb') as mf:
         self.assertEqual(attachment.decode('utf-8'), mf.read().decode('utf-8'))
Example #8
0
 def test_alternative(self):
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     self.assertTrue(
         mail.send(to=['*****@*****.**'],
                   message=('Text only',
                            '<html><pre>HTML Only</pre></html>')))
     message = TestMail.DummySMTP.inbox.pop()
     self.assertTrue(message.parsed_payload.is_multipart())
     self.assertTrue(message.parsed_payload.get_content_type() ==
                     'multipart/alternative')
     parts = message.parsed_payload.get_payload()
     self.assertTrue('Text only' in parts[0].as_string())
     self.assertTrue(
         '<html><pre>HTML Only</pre></html>' in parts[1].as_string())
Example #9
0
 def test_attachment(self):
     module_file = os.path.abspath(__file__)
     mail = Mail()
     mail.settings.server = 'smtp.example.com:25'
     mail.settings.sender = '*****@*****.**'
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               subject='hello',
                               message='world',
                               attachments=Mail.Attachment(module_file)))
     message = TestMail.DummySMTP.inbox.pop()
     import email
     parsed_msg = email.message_from_string(message.payload)
     attachment = parsed_msg.get_payload(1).get_payload(decode=True)
     with open(module_file, 'rb') as mf:
         self.assertEqual(attachment.decode('utf-8'), mf.read().decode('utf-8'))
     # Test missing attachment name error
     stream = open(module_file)
     self.assertRaises(Exception, lambda *args, **kwargs: Mail.Attachment(*args, **kwargs), stream)
     stream.close()
     # Test you can define content-id and content type
     self.assertTrue(mail.send(to=['*****@*****.**'],
                               subject='hello',
                               message='world',
                               attachments=Mail.Attachment(module_file, content_id='trololo', content_type='tra/lala')))
     message = TestMail.DummySMTP.inbox.pop()
     self.assertTrue('Content-Type: tra/lala' in message.payload)
     self.assertTrue('Content-Id: <trololo>' in message.payload)
Example #10
0
from globals import current
from html import *
from validators import *
from http import redirect, HTTP
from dal import DAL, Field
from sqlhtml import SQLFORM, SQLTABLE
from compileapp import LOAD

# Dummy code to enable code completion in IDE's.
if 0:
    from globals import Request, Response, Session
    from cache import Cache
    from languages import translator
    from tools import Auth, Crud, Mail, Service, PluginManager

    # API objects
    request = Request()
    response = Response()
    session = Session()
    cache = Cache(request)
    T = translator(request)

    # Objects commonly defined in application model files
    # (names are conventions only -- not part of API)
    db = DAL()
    auth = Auth(db)
    crud = Crud(db)
    mail = Mail()
    service = Service()
    plugins = PluginManager()