def test_simple_send_using_ssl(self): pipeline = FakePipeline() pipeline_dependency = dependencies.InstanceDependency(pipeline) pipeline_dependency.is_ready = True self.runtime_environment.configure() data_dir = filepath.FilePath(__file__).sibling('data') private_key = data_dir.child('server.key').path cert_key = data_dir.child('server.crt').path self.create_smtp_server( listen = 'ssl:%i'+':interface=localhost:privateKey=%s:certKey=%s'%(private_key, cert_key), checker = dict( name = 'twisted.cred.checkers.InMemoryUsernamePasswordDatabaseDontUse', arguments = dict( username = '******' ) ) ) self.application.startService() self.addCleanup(self.application.stopService) self.server.pipeline_dependency = self.pipeline_dependency # sending an email without authorizing should not work sending = smtp_provider.send_mail( from_addr='*****@*****.**', to_addr='*****@*****.**', file='hello', port=self.port, use_ssl=True, ) try: yield sending except smtp.SMTPDeliveryError as e: self.assertEquals(e.code, 550) else: self.fail('SMTPDeliveryError not raised.') # .. but sending an email after authentication should be fine: yield smtp_provider.send_mail( from_addr='*****@*****.**', to_addr='*****@*****.**', file='hello after login', username='******', password='******', port=self.port, use_ssl=True, ) # the email should have arrived self.assertEquals(len(self.pipeline.batons), 1) baton = self.pipeline.batons[0] self.assertEquals(baton['from_addr'], '*****@*****.**') self.assertEquals(baton['to_addr'], '*****@*****.**') # since we logged in, the avatar_id should be in the baton: self.assertEquals(baton['avatar_id'], 'username') # the payload should contain our text :) self.assertEquals(baton['message'].get_payload(), 'hello after login\n')
def process(self, baton): message = util.dict_get_path(baton, self.message_path) from_addr = self.from_addr if not from_addr: from_addr = util.dict_get_path(baton, self.from_path) to_addr = self.to_addr if not to_addr: to_addr = util.dict_get_path(baton, self.to_path) yield smtp_provider.send_mail(from_addr, to_addr, message, **self.configuration) defer.returnValue(baton)
def test_custom_received_header(self): self.runtime_environment.configure() # create a custom received header: self.create_smtp_server(received_header='proto, helo, origin, recipients: "Received: by test_custom_header.local"') self.application.startService() self.addCleanup(self.application.stopService) self.server.pipeline_dependency = self.pipeline_dependency yield smtp_provider.send_mail('*****@*****.**', '*****@*****.**', 'Test message', port=self.port) # we should have processed 1 baton, which contains an email message with our custom received header: self.assertEquals(len(self.pipeline.batons), 1) baton = self.pipeline.batons[0] self.assertEquals(baton['message']['Received'], 'by test_custom_header.local')