Commits

Anonymous committed 099f9c9

more minor changes

Comments (0)

Files changed (2)

pyramid_lamson/__init__.py

 
 from pyramid_lamson.mail.connection import Connection
 from pyramid_lamson.mail.message import Message
-from pyramid_lamson.mail_message import Attachment
-from pyramid_lamson.mail_message import BadHeaderError
-from pyramid_lamson.mail.signals import email_dispatched
+from pyramid_lamson.mail.message import Attachment
+from pyramid_lamson.mail.message import BadHeaderError
 
 
 class Mailer(object):
 
     Usage:
 
-    config.registry['mailer'] = Mailer(config.settings)
+    config.registry['mailer'] = Mailer(config)
 
     """
 
-    def __init__(self, settings):
+    def __init__(self, config):
         
         """
         Initializes your mail settings from the application
         settings.
 
-        You can use this if you want to set up your Mail instance
-        at configuration time.
-
-        :param app: Flask application instance
         """
 
-        self.server = settings.get('mail_server', '127.0.0.1')
-        self.username = settings.get('mail_username')
-        self.password = settings.get('mail_password')
-        self.port = settings.get('mail_port', 25)
-        self.use_tls = settings.get('mail_use_tls', false)
-        self.use_ssl = settings.get('mail_use_ssl', false)
-        self.debug = int(settings.get('mail_debug', app.debug))
-        self.max_emails = settings.get('default_max_emails')
-        self.suppress = settings.get('mail_suppress_send', false)
-        self.fail_silently = settings.get('mail_fail_silently', true)
+        self.config = config
+
+        self.server = config.settings.get('mail:server', '127.0.0.1')
+        self.username = config.settings.get('mail:username')
+        self.password = config.settings.get('mail:password')
+        self.port = config.settings.get('mail:port', 25)
+        self.use_tls = config.settings.get('mail:use_tls', false)
+        self.use_ssl = config.settings.get('mail:use_ssl', false)
+        self.debug = int(config.settings.get('mail:debug', app.debug))
+        self.max_emails = config.settings.get('mail:max_emails')
+        self.suppress = config.settings.get('mail:suppress_send', false)
+        self.fail_silently = config.settings.get('mail:fail_silently', true)
 
     def send(self, message):
         """
 
         :param message: a Message instance.
         """
+        # self.config.notify.notify(ISentMessage, message)
 
         with self.connect() as connection:
             message.send(connection)
 
         Takes same arguments as Message constructor.
     
-        :versionadded: 0.3.5
         """
 
         self.send(Message(*args, **kwargs))

pyramid_lamson/connection.py

 
     """Handles connection to host."""
 
-    def __init__(self, mail, max_emails=None):
+    def __init__(self, mailer, max_emails=None):
 
-        self.mail = mail
-        self.app = self.mail.app
-        self.suppress = self.mail.suppress
-        self.max_emails = max_emails or self.mail.max_emails or 0
-        self.fail_silently = self.mail.fail_silently
+        self.mailer = mailer
+        self.suppress = self.mailer.suppress
+        self.max_emails = max_emails or self.mailer.max_emails or 0
+        self.fail_silently = self.mailer.fail_silently
 
     def __enter__(self):
 
     def configure_host(self):
         
         try:
-            if self.mail.use_ssl:
-                host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
+            if self.mailer.use_ssl:
+                host = smtplib.SMTP_SSL(self.mailer.server, self.mailer.port)
             else:
-                host = smtplib.SMTP(self.mail.server, self.mail.port)
+                host = smtplib.SMTP(self.mailer.server, self.mailer.port)
         except socket.error:
             if self.fail_silently:
                 return
 
         host.set_debuglevel(int(self.app.debug))
 
-        if self.mail.use_tls:
+        if self.mailer.use_tls:
             host.starttls()
-        if self.mail.username and self.mail.password:
-            host.login(self.mail.username, self.mail.password)
+        if self.mailer.username and self.mailer.password:
+            host.login(self.mailer.username, self.mailer.password)
 
         return host
 
         Shortcut for send(msg). 
 
         Takes same arguments as Message constructor.
-    
-        :versionadded: 0.3.5
-
         """
 
         self.send(Message(*args, **kwargs))