Raimon Esteve (Zikzakmedia) avatar Raimon Esteve (Zikzakmedia) committed b587af6

SMTP module dependence. Send email by SMTP Servers

Comments (0)

Files changed (3)

     #: is infact the source record to generate an electronic mail
     electronic_mail = fields.Many2One(
         'electronic.mail', 'Email', required=True, ondelete='CASCADE')
+    smtp_server = fields.Many2One('smtp.server', 'SMTP Server', 
+        domain=[('state', '=', 'done')], required=True)
     name = fields.Char('Name', required=True)
     model = fields.Many2One(
         'ir.model', 'Model', required=True, select="1")
             'smtp_error': 'Wrong connection to SMTP server. Email have not sent',
             'recipients_error': 'Not valid recipients emails. Check emails in TO, CC or BBC',
+            'smtp_server_default': 'There are not default SMTP server',
         :param template: Browse Record of the template
         ElectronicMail = Pool().get('electronic.mail')
+        SMTP = Pool().get('smtp.server')
         email = ElectronicMail(email_id)
         recepients = recepients_from_fields(email)
+        """SMTP Server from template or default"""
+        if not template:
+            servers = SMTP.search([('state','=','done'),('default','=',True)])
+            if not len(servers)>0:
+                self.raise_user_error('smtp_server_default')
+        server = template and template.smtp_server or servers[0]
         """Validate recipients to send or move email to draft mailbox"""
         emails = ",".join(recepients)
-        if not ElectronicMail.get_email_valid(emails):
-            if not template:
-                self.raise_user_error('recipients_error')
+        if not ElectronicMail.get_email_valid(emails) and template:
             """Draft Mailbox. Not send email"""
             ElectronicMail.write([email], {
                 'mailbox': template.draft_mailbox,
             return False
-            server = get_smtp_server()
+            server = SMTP.get_smtp_server(server)
             server.sendmail(email.from_, recepients,
         <field name="language"/>
         <field name="engine"/>
         <field name="subject"/>
+        <field name="smtp_server"/>
         <field name="name"/>
         <label name="model"/>
         <field name="model"/>
+        <label name="smtp_server"/>
+        <field name="smtp_server"/>
         <label name="language"/>
         <field name="language"/>
         <notebook colspan="4">
+    smtp
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.