def index():
    # send an email
    msg = Message("*****@*****.**",
                  "*****@*****.**",
                  "a subject")
    msg.plain = "body of message"
    msg.send()
class TestTurboGearsConfigWorks(SMTPTestCase):
    
    def setUp(self):
        real_config = {'mail.on': True, 'mail.manager': 'immediate', 
                       'mail.transport': 'smtp', 'mail.brand': False}
        self.config = TurboGearsFakeConfig(real_config)
        self.fake_setuptools =  {'immediate': ImmediateManager,
                                 'smtp': SMTPTransportFactory()}
        super(TestTurboGearsConfigWorks, self).setUp()
        
        self.msg = Message('*****@*****.**', '*****@*****.**', 'Test', 
                           plain='Plain text body')
    
    def tearDown(self):
        interface.stop(force=True)
        interface.config = {'mail.on': False}
        super(TestTurboGearsConfigWorks, self).tearDown()
    
    def init_mta(self, policy_class=IMTAPolicy):
        super(TestTurboGearsConfigWorks, self).init_mta(policy_class)
        self.connection_string = '%s:%s' % (self.hostname, self.listen_port)
        self.config.update({'mail.smtp.server': self.connection_string})
        # We must not assume that TurboMail is installed with egg-info
        interface.start(self.config, extra_classes=self.fake_setuptools)
    
    
    def test_message_sending_does_not_assume_dict_for_interface_config(self):
        self.msg.send()
        
        queue = self.deliverer.received_messages
        self.assertEqual(1, queue.qsize())
 def setUp(self):
     real_config = {'mail.on': True, 'mail.manager': 'immediate', 
                    'mail.transport': 'smtp', 'mail.brand': False}
     self.config = TurboGearsFakeConfig(real_config)
     self.fake_setuptools =  {'immediate': ImmediateManager,
                              'smtp': SMTPTransportFactory()}
     super(TestTurboGearsConfigWorks, self).setUp()
     
     self.msg = Message('*****@*****.**', '*****@*****.**', 'Test', 
                        plain='Plain text body')
Exemple #4
0
 def sendmail(self, subject, to, text=None, attachments=()):
     message = Message(encoding="utf-8")
     message.author = self.AUTHOR
     message.subject = subject
     message.to = to
     if text is None:
         text = " "
     message.plain = text
     for name, attachment in attachments:
         message.attach(StringIO(attachment), name)
     tries = 2
     while tries > 0:
         try:
             interface.send(message)
         except socket_error:
             tries -= 1
             if not tries:
                 raise
         else:
             break