def sendMail( self, address, subject, body, fromAddress = None, localAttempt = True, html = False ): """ Send an e-mail with subject and body to the specified address. Try to send from local area before central service by default. """ self.log.verbose( 'Received signal to send the following mail to %s:\nSubject = %s\n%s' % ( address, subject, body ) ) result = S_ERROR() if localAttempt: try: m = Mail() m._subject = subject m._message = body m._mailAddress = address m._html = html if fromAddress: m._fromAddress = fromAddress result = m._send() except Exception as x: self.log.warn( 'Sending mail failed with exception:\n%s' % ( str( x ) ) ) if result['OK']: self.log.verbose( 'Mail sent successfully from local host to %s with subject %s' % ( address, subject ) ) self.log.debug( result['Value'] ) return result self.log.warn( 'Could not send mail with the following message:\n%s\n will attempt to send via NotificationService' % result['Message'] ) notify = self.__getRPCClient( timeout = 120 ) result = notify.sendMail( address, subject, body, str( fromAddress ) ) if not result['OK']: self.log.error( 'Could not send mail via central Notification service', result['Message'] ) else: self.log.verbose( result['Value'] ) return result
def sendMail(self, addresses, subject, body, fromAddress=None, localAttempt=True, html=False): """Send an e-mail with subject and body to the specified address. Try to send from local area before central service by default. """ self.log.verbose( "Received signal to send the following mail to %s:\nSubject = %s\n%s" % (addresses, subject, body)) result = S_ERROR() if not fromAddress: fromAddress = "" addresses = [addresses] if isinstance(addresses, str) else list(addresses) for address in addresses: if localAttempt: try: m = Mail() m._subject = subject m._message = body m._mailAddress = address m._html = html if fromAddress: m._fromAddress = fromAddress result = m._send() except Exception as x: self.log.warn("Sending mail failed with exception:\n%s" % (str(x))) if result["OK"]: self.log.verbose( "Mail sent successfully from local host to %s with subject %s" % (address, subject)) self.log.debug(result["Value"]) return result self.log.warn( "Could not send mail with the following message:\n%s\n will attempt to send via NotificationService" % result["Message"]) result = self._getRPC().sendMail(address, subject, body, fromAddress) if not result["OK"]: self.log.error( "Could not send mail via central Notification service", result["Message"]) return result else: self.log.verbose(result["Value"]) return result
def sendMail(self, address, subject, body, fromAddress=None, localAttempt=True, html=False): """ Send an e-mail with subject and body to the specified address. Try to send from local area before central service by default. """ self.log.verbose( 'Received signal to send the following mail to %s:\nSubject = %s\n%s' % (address, subject, body)) result = S_ERROR() if localAttempt: try: m = Mail() m._subject = subject m._message = body m._mailAddress = address m._html = html if fromAddress: m._fromAddress = fromAddress result = m._send() except Exception as x: self.log.warn('Sending mail failed with exception:\n%s' % (str(x))) if result['OK']: self.log.verbose( 'Mail sent successfully from local host to %s with subject %s' % (address, subject)) self.log.debug(result['Value']) return result self.log.warn( 'Could not send mail with the following message:\n%s\n will attempt to send via NotificationService' % result['Message']) notify = self.__getRPCClient(timeout=120) result = notify.sendMail(address, subject, body, str(fromAddress)) if not result['OK']: self.log.error( 'Could not send mail via central Notification service', result['Message']) else: self.log.verbose(result['Value']) return result