def export_sendMail( self, address, subject, body, fromAddress, avoidSpam = False ): """ Send an email with supplied body to the specified address using the Mail utility. if avoidSpam is True, then emails are first added to a set so that duplicates are removed, and sent every hour. """ gLogger.verbose( 'Received signal to send the following mail to %s:\nSubject = %s\n%s' % ( address, subject, body ) ) eMail = Mail() notificationSection = PathFinder.getServiceSection( "Framework/Notification" ) csSection = notificationSection + '/SMTPServer' eMail._smtpHost = gConfig.getValue( '%s/Host' % csSection ) eMail._smtpPort = gConfig.getValue( '%s/Port' % csSection ) eMail._smtpLogin = gConfig.getValue( '%s/Login' % csSection ) eMail._smtpPasswd = gConfig.getValue( '%s/Password' % csSection ) eMail._smtpPtcl = gConfig.getValue( '%s/Protocol' % csSection ) eMail._subject = subject eMail._message = body eMail._mailAddress = address if not fromAddress == 'None': eMail._fromAddress = fromAddress if gConfig.getValue( '%s/FromAddress' % csSection ): eMail._fromAddress = gConfig.getValue( '%s/FromAddress' % csSection ) if avoidSpam: gMailSet.add(eMail) return S_OK("Mail added to gMailSet") else: result = eMail._send() if not result['OK']: gLogger.warn( 'Could not send mail with the following message:\n%s' % result['Message'] ) else: gLogger.info( 'Mail sent successfully to %s with subject %s' % ( address, subject ) ) gLogger.debug( result['Value'] ) return result
def export_sendMail( self, address, subject, body, fromAddress, avoidSpam = False ): """ Send an email with supplied body to the specified address using the Mail utility. if avoidSpam is True, then emails are first added to a set so that duplicates are removed, and sent every hour. """ gLogger.verbose( 'Received signal to send the following mail to %s:\nSubject = %s\n%s' % ( address, subject, body ) ) eMail = Mail() notificationSection = PathFinder.getServiceSection( "Framework/Notification" ) csSection = notificationSection + '/SMTP' eMail._smtpHost = gConfig.getValue( '%s/Host' % csSection ) eMail._smtpPort = gConfig.getValue( '%s/Port' % csSection ) eMail._smtpLogin = gConfig.getValue( '%s/Login' % csSection ) eMail._smtpPasswd = gConfig.getValue( '%s/Password' % csSection ) eMail._smtpPtcl = gConfig.getValue( '%s/Protocol' % csSection ) eMail._subject = subject eMail._message = body eMail._mailAddress = address if not fromAddress == 'None': eMail._fromAddress = fromAddress if gConfig.getValue( '%s/FromAddress' % csSection ): eMail._fromAddress = gConfig.getValue( '%s/FromAddress' % csSection ) if avoidSpam: gMailSet.add(eMail) return S_OK("Mail added to gMailSet") else: result = eMail._send() if not result['OK']: gLogger.warn( 'Could not send mail with the following message:\n%s' % result['Message'] ) else: gLogger.info( 'Mail sent successfully to %s with subject %s' % ( address, subject ) ) gLogger.debug( result['Value'] ) return result
def export_sendMail(self, address, subject, body, fromAddress, avoidSpam=False): """ Send an email with supplied body to the specified address using the Mail utility. :param basestring address: recipient addresses :param basestring subject: subject of letter :param basestring body: body of letter :param basestring fromAddress: sender address, if None, will be used default from CS :param bool avoidSpam: if True, then emails are first added to a set so that duplicates are removed, and sent every hour. :return: S_OK(basestring)/S_ERROR() -- basestring is status message """ gLogger.verbose( 'Received signal to send the following mail to %s:\nSubject = %s\n%s' % (address, subject, body)) if gMailCache.exists(hash(address + subject + body)) and not avoidSpam: return S_OK( 'Email with the same content already sent today to current addresses, come back tomorrow' ) eMail = Mail() notificationSection = PathFinder.getServiceSection( "Framework/Notification") csSection = notificationSection + '/SMTP' eMail._smtpHost = gConfig.getValue('%s/Host' % csSection) eMail._smtpPort = gConfig.getValue('%s/Port' % csSection) eMail._smtpLogin = gConfig.getValue('%s/Login' % csSection) eMail._smtpPasswd = gConfig.getValue('%s/Password' % csSection) eMail._smtpPtcl = gConfig.getValue('%s/Protocol' % csSection) eMail._subject = subject eMail._message = body eMail._mailAddress = address if not fromAddress == 'None': eMail._fromAddress = fromAddress eMail._fromAddress = gConfig.getValue( '%s/FromAddress' % csSection) or eMail._fromAddress if avoidSpam and eMail in gMailSet: return S_OK("Mail already sent") else: result = eMail._send() if not result['OK']: gLogger.warn( 'Could not send mail with the following message:\n%s' % result['Message']) else: gMailCache.add(hash(address + subject + body), 3600 * 24) gLogger.info('Mail sent successfully to %s with subject %s' % (address, subject)) gLogger.debug(result['Value']) if avoidSpam: gMailSet.add(eMail) return result
def export_sendMail(self, address, subject, body, fromAddress, avoidSpam=False): """ Send an email with supplied body to the specified address using the Mail utility. :param six.string_types address: recipient addresses :param six.string_types subject: subject of letter :param six.string_types body: body of letter :param six.string_types fromAddress: sender address, if None, will be used default from CS :param bool avoidSpam: Deprecated :return: S_OK(six.string_types)/S_ERROR() -- six.string_types is status message """ self.log.verbose( 'Received signal to send the following mail to %s:\nSubject = %s\n%s' % (address, subject, body)) if self.mailCache.exists(hash(address + subject + body)): return S_OK( 'Email with the same content already sent today to current addresses, come back tomorrow' ) eMail = Mail() notificationSection = PathFinder.getServiceSection( "Framework/Notification") csSection = notificationSection + '/SMTP' eMail._smtpHost = gConfig.getValue('%s/Host' % csSection) eMail._smtpPort = gConfig.getValue('%s/Port' % csSection) eMail._smtpLogin = gConfig.getValue('%s/Login' % csSection) eMail._smtpPasswd = gConfig.getValue('%s/Password' % csSection) eMail._smtpPtcl = gConfig.getValue('%s/Protocol' % csSection) eMail._subject = subject eMail._message = body eMail._mailAddress = address if not fromAddress == 'None': eMail._fromAddress = fromAddress eMail._fromAddress = gConfig.getValue( '%s/FromAddress' % csSection) or eMail._fromAddress result = eMail._send() if not result['OK']: self.log.warn( 'Could not send mail with the following message:\n%s' % result['Message']) else: self.mailCache.add(hash(address + subject + body), 3600 * 24) self.log.info('Mail sent successfully to %s with subject %s' % (address, subject)) self.log.debug(result['Value']) return result
def export_sendMail(self, address, subject, body, fromAddress): """Send an email with supplied body to the specified address using the Mail utility. :param str address: recipient addresses :param str subject: subject of letter :param str body: body of letter :param str fromAddress: sender address, if "", will be used default from CS :return: S_OK(str)/S_ERROR() -- str is status message """ self.log.verbose( "Received signal to send the following mail to %s:\nSubject = %s\n%s" % (address, subject, body)) if self.mailCache.exists(hash(address + subject + body)): return S_OK( "Email with the same content already sent today to current addresses, come back tomorrow" ) eMail = Mail() notificationSection = PathFinder.getServiceSection( "Framework/Notification") csSection = notificationSection + "/SMTP" eMail._smtpHost = gConfig.getValue("%s/Host" % csSection) eMail._smtpPort = gConfig.getValue("%s/Port" % csSection) eMail._smtpLogin = gConfig.getValue("%s/Login" % csSection) eMail._smtpPasswd = gConfig.getValue("%s/Password" % csSection) eMail._smtpPtcl = gConfig.getValue("%s/Protocol" % csSection) eMail._subject = subject eMail._message = body eMail._mailAddress = address if fromAddress: eMail._fromAddress = fromAddress eMail._fromAddress = gConfig.getValue( "%s/FromAddress" % csSection) or eMail._fromAddress result = eMail._send() if not result["OK"]: self.log.warn( "Could not send mail with the following message:\n%s" % result["Message"]) else: self.mailCache.add(hash(address + subject + body), 3600 * 24) self.log.info("Mail sent successfully to %s with subject %s" % (address, subject)) self.log.debug(result["Value"]) return result