@@ -0,0 +1,2197 @@
+import json%0Aimport logging%0Aimport smtplib%0A%0Afrom orchestrator.common.util import RestOperations%0A%0Alogger = logging.getLogger('orchestrator_core')%0A%0A%0Aclass MailerOperations(object):%0A%0A    def __init__(self,%0A                 MAILER_PROTOCOL=None,%0A                 MAILER_HOST=None,%0A                 MAILER_PORT=None,%0A                 CORRELATOR_ID=None,%0A                 TRANSACTION_ID=None):%0A        self.MAILER_PROTOCOL = MAILER_PROTOCOL%0A        self.MAILER_HOST = MAILER_HOST%0A        self.MAILER_PORT = int(MAILER_PORT)%0A%0A        # TODO: read from config%0A        self.smtp_from%0A        self.smtp_server%0A        self.smtp_port%0A        self.smtp_user%0A        self.smtp_password%0A        %0A%0A    def checkMailer(self):%0A        #conn = ldap.open(self.LDAP_HOST, self.LDAP_PORT)%0A        assert conn != None%0A    %0A%0A    def send_email(self, to, subject, text):%0A%0A        dest = %5Bto%5D # must be a list%0A%0A        #%0A        # Prepare actual message%0A        #%0A        mail_headers = (%22From: %5C%22%25s%5C%22 %3C%25s%3E%5Cr%5CnTo: %25s%5Cr%5Cn%22%0A                        %25 (self.smtp_from,%0A                           self.smtp_from,%0A                           %22, %22.join(dest)))%0A%0A        msg = mail_headers%0A        msg += (%22Subject: %25s%5Cr%5Cn%5Cr%5Cn%22 %25 subject)%0A        msg += text%0A%0A        #%0A        # Send the mail%0A        #%0A        try:%0A            # TODO: server must be initialized by current object%0A            server = smtplib.SMTP(self.smtp_server,%0A                                  self.smtp_port)%0A        except smtplib.socket.gaierror:%0A            logger.error('SMTP socket error')%0A            return False%0A%0A        server.ehlo()%0A        server.starttls()%0A        server.ehlo%0A%0A        try:%0A            server.login(self.smtp_user,%0A                         self.smtp_password)%0A        except smtplib.SMTPAuthenticationError:%0A            logger.error('SMTP authentication error')%0A            return False%0A%0A        try:%0A            server.sendmail(self.smtp_from, dest, msg)%0A        except Exception:  # try to avoid catching Exception unless you have too%0A            logger.error('SMTP autentication error')%0A            return False%0A        finally:%0A            server.quit()%0A        logger.info('email was sent')            %0A        return True%0A

add mailer