(self, actionName, success, messages)
Send an email with the result of an action using the local mail server
Send an email with the result of an action using the local mail server
Send an email with the result of an action using the local mail server
def sendEmail(self, actionName, success, messages):
        """Send an email with the result of an action using the local mail server"""

        # Import smtplib for the actual sending function
        import smtplib

        # Import the email modules we'll need
        from email.mime.text import MIMEText
        from email.mime.multipart import MIMEMultipart

        # Build a simple reporting backup info
        msg = MIMEMultipart()
        subject = 'Backup {0} for {1}: {2}'.format(
            actionName,
            self.configName,
            'Success' if success else 'Error')

        msg.preamble = subject

        for message in messages:
            msg.preamble += "\r\n" + message

        # Add message body
        summary = MIMEText(msg.preamble)
        msg.attach(summary)

        # Add all backup action output / error logs.
        # This can be create, prune, check or restore
        for infoName in self.lastBackupInfo.keys():
            infoReport = MIMEText(self.lastBackupInfo[infoName])
            infoReport.add_header('Content-Disposition', 'inline; filename="{0}.log"'.format(infoName))
            msg.attach(infoReport)

        # This can be used for automatic filtering with Sieve
        msg.add_header('X-Postmaster-Alert', 'backup')

        # Basic headers for the message
        msg['Subject'] = subject
        msg['From'] = self.alerts_from
        msg['To'] = self.alerts_recipient

        # Send the message via our own SMTP server,
        # but don't include the envelope header.
        session = smtplib.SMTP('localhost')
        session.sendmail(self.alerts_from, [ self.alerts_recipient ], msg.as_string())
        session.quit()
def sendEmail ( self , actionName , success , messages ) : # Import smtplib for the actual sending function import smtplib # Import the email modules we'll need from email . mime . text import MIMEText from email . mime . multipart import MIMEMultipart # Build a simple reporting backup info msg = MIMEMultipart ( ) subject = 'Backup {0} for {1}: {2}' . format ( actionName , self . configName , 'Success' if success else 'Error' ) msg . preamble = subject for message in messages : msg . preamble += "\r\n" + message # Add message body summary = MIMEText ( msg . preamble ) msg . attach ( summary ) # Add all backup action output / error logs. # This can be create, prune, check or restore for infoName in self . lastBackupInfo . keys ( ) : infoReport = MIMEText ( self . lastBackupInfo [ infoName ] ) infoReport . add_header ( 'Content-Disposition' , 'inline; filename="{0}.log"' . format ( infoName ) ) msg . attach ( infoReport ) # This can be used for automatic filtering with Sieve msg . add_header ( 'X-Postmaster-Alert' , 'backup' ) # Basic headers for the message msg [ 'Subject' ] = subject msg [ 'From' ] = self . alerts_from msg [ 'To' ] = self . alerts_recipient # Send the message via our own SMTP server, # but don't include the envelope header. session = smtplib . SMTP ( 'localhost' ) session . sendmail ( self . alerts_from , [ self . alerts_recipient ] , msg . as_string ( ) ) session . quit ( )