Beispiel #1
0
def emailProjectEndorsement(email, title, leaderName):
    """
    Email project admins about endorsements.  Using template: project_endorsement
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    subject = "%s liked your project!" % leaderName
    template_values = {
        'title': title,
        'leader_name': leaderName,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/project_endorsement', template_values, suffix = 'txt')
         
    # Send email.
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])
    except Exception, e:
        log.info("*** couldn't send endorsement email")
        log.error(e)
        return False
Beispiel #2
0
def emailTempPassword(email, password):
    """
    Email temporary password.  Using template: forgot_password
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    subject = "Your password has been reset"
    link = "%slogin" % Config.get('default_host')
    link = "%stou" % Config.get('default_host')
    template_values = {
        'password': password,
        'link': link,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/forgot_password', template_values, suffix = 'txt')

    # Send email.
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])
    except Exception, e:
        log.info("*** couldn't send forgot password email")
        log.error(e)
        return False
Beispiel #3
0
def emailUnauthenticatedUser(email, authGuid):
    """
    Send unauthenticated user a link to authenticate.  Using 
    template: auth_user
        
    @type   email: string
    @param  email: Email address to send to
    
    @rtype: *
    @returns: Emailer send response.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    subject = "Please authenticate your account"
    link = "%sjoin/auth/%s" % (Config.get('default_host'), authGuid)
    template_values = {
        'link': link,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/auth_user', template_values, suffix = 'txt')
            
    # Send email.            
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])  
    except Exception, e:
        log.info("*** couldn't send authenticate user email")
        log.error(e)
        return False
Beispiel #4
0
def emailAccountDeactivation(email):
    """
    Email deleted users.  Using template: account_deactivation
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    subject = "Your account has been deactivated"
    link = "%stou" % Config.get('default_host')
    template_values = {
        'link': link,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/account_deactivation', template_values, suffix = 'txt')

    # Send email.
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])
    except Exception, e:
        log.info("*** couldn't send account deactivation email")
        log.error(e)
        return False
Beispiel #5
0
def emailResourceApproval(email, title):
    """
    Email resource owner on approval.  Using template: resource_approval
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    subject = "Your resource has been approved"
    template_values = {
        'link': Config.get('default_host'),
        'title': title,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/resource_approval', template_values, suffix = 'txt')

    # Send email.
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])  
    except Exception, e:
        log.info("*** couldn't send resource approval email")
        log.error(e)
        return False
 def sendEmail(self, to=None, recipients=None, subject=None, body=None, maxRetries=10):
     complete = False
     failNum = 0
     
     while not complete:
         complete = Emailer.send(addresses=to,
                     subject=subject,
                     text=None,
                     html=body,
                     from_name = self.MailerSettings.get('FromName'),
                     from_address = self.MailerSettings.get('FromEmail'),
                     bcc=recipients)
                     
         if (not complete):
             if (failNum < maxRetries):
                 failNum += 1
                 
                 # Most probably we got an SES error, which means we should wait and retry
                 time.sleep(1)
                 pass
             else:
                 complete = True
                 logging.error("Failed to send digest email '%s'. Quit after %s tries." % (subject, str(maxRetries)))
                 
                 return False
     
     return True
Beispiel #7
0
    def sendEmail(self,
                  to=None,
                  recipients=None,
                  subject=None,
                  body=None,
                  maxRetries=10):
        complete = False
        failNum = 0

        while not complete:
            complete = Emailer.send(
                addresses=to,
                subject=subject,
                text=None,
                html=body,
                from_name=self.MailerSettings.get('FromName'),
                from_address=self.MailerSettings.get('FromEmail'),
                bcc=recipients)

            if (not complete):
                if (failNum < maxRetries):
                    failNum += 1

                    # Most probably we got an SES error, which means we should wait and retry
                    time.sleep(1)
                    pass
                else:
                    complete = True
                    logging.error(
                        "Failed to send digest email '%s'. Quit after %s tries."
                        % (subject, str(maxRetries)))

                    return False

        return True
Beispiel #8
0
def directMessageUser(db, toUserId, toName, toEmail, fromUserId, fromName, message):
    """
    Email user about direct message.  Using template: direct_message
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    #email = "%s <%s>" % (toName, toEmail)
    email = toEmail
    subject = "Change By Us message from %s" % fromName
    link = "%suseraccount/%s" % (Config.get('default_host'), fromUserId)
    template_values = {
        'name': fromName,
        'message': message,
        'link': link,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/direct_message', template_values, suffix = 'txt')

    # Send email.
    try:
        isSent = Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])
                                                       
        if (isSent):
            db.insert('direct_message', message = message, to_user_id = toUserId, from_user_id = fromUserId)
            return True
        else:
            log.info("*** couldn't log direct message")
            # Not sure if best to return False
            return False

    except Exception, e:
        log.info("*** couldn't send direct message email")
        log.error(e)
        return False
    def createDigests(self, store_to_db=True, mark=None):
        """ Create the digests based on FromDate and ToDate """
        if self.FromDate is None or self.ToDate is None:
            if mark is None:
                logging.error("Cannot proceed since there's no time range to get the digests for!")
                return False
            else:
                # Set the date range to yesterday
                # TODO: This really should be a lot more configurable!
                td = datetime.date(mark)
                fd = td + relativedelta(days=-1)
                self.FromDate = str(fd)
                self.ToDate = str(td)
                logging.info('Getting digests for date range: %s to %s' % (fd, td))

        resp = self.getDataToCreateDigest()
        base_url = self.Config.get('default_host')
        member_profile_url = "%suseraccount/" % base_url
        digests = {}
        for projId in resp.keys():
            # Ignore all empty projects, and projects that have no recipients
            if ((resp[projId].get('members') is None or len(resp[projId].get('members')) == 0) and\
                (resp[projId].get('messages') is None or len(resp[projId].get('messages')) == 0)) or\
                resp[projId].get('recipients') is None or len(resp[projId].get('recipients')) == 0:
               continue
            
            # Initialize the digest data structure
            if digests.get(projId) is None:
                digests[projId] = {'members':[], 'messages':[], 'recipients': ""}

            digests[projId]['recipients'] = resp[projId].get('recipients')
            digests[projId]['title'] = resp[projId].get('title')
            digests[projId]['project_id'] = projId
            digests[projId]['num_members'] = resp[projId].get('num_members')
            digests[projId]['active_goal_description'] = resp[projId].get('active_goal_description')
            digests[projId]['link'] = "<a href='%sproject/%s'>%s</a>" % (self.Config.get('default_host'), projId, resp[projId].get('title'))

            if resp[projId].get('members') is not None and len(resp[projId].get('members')) > 0:
                digests[projId]['members'] = resp[projId].get('members')
            
            if resp[projId].get('messages') is not None and len(resp[projId].get('messages')) > 0:
                digests[projId]['messages'] = resp[projId].get('messages')

        # Store the formatted body
        for digest in digests:
            currentDigest = digests.get(digest)
            currentDigest['subject'] = "%s%s\n\n" % (self.Config.get('email').get('digest').get('digest_subject_prefix'), currentDigest.get('title'))
            currentDigest['body'] = Emailer.render('email/digest', 
                                                   {'digest':currentDigest,
                                                   'baseUrl':base_url,
                                                   'contactEmail':self.Config.get('email').get('from_email')})

        # Store it for later consumption
        logging.info('Created digests (in DB) for %s projects' % len(digests.keys()))
        self.Digests = digests
        return True
Beispiel #10
0
def emailResourceNotification(email, projectId, title, description, resourceName):
    """
    Email resource contacts on resource add.  Using template: resource_notification
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    subject = "A project on Changeby.us has added %s as a resource" % resourceName
    link = "%sproject/%s" % (Config.get('default_host'), str(projectId))
    template_values = {
        'title': title,
        'description': description,
        'resource_name': resourceName,
        'link': link,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/resource_notification', template_values, suffix = 'txt')
    
    # If dev, don't email resources
    if (Config.get('dev')):
        log.info("*** body = %s" % body)
        return True

    # Send email.
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])
    except Exception, e:
        log.info("*** couldn't send resource notification email")
        log.error(e)
        return False
Beispiel #11
0
def emailProjectJoin(email, projectId, title, userId, userName):
    """
    Email project admins when new user joins.  Using template: project_join
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    defaultUrl = Config.get('default_host')
    subject = "A new member %s has joined your project %s" % (userName, title)
    userLink = "%suseraccount/%s" % (defaultUrl, str(userId))
    memberLink = "%sproject/%s#show,members" % (defaultUrl, str(projectId))
    template_values = {
        'title': title,
        'user_name': userName,
        'user_link': userLink,
        'member_link': memberLink,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/project_join', template_values, suffix = 'txt')
         
    # Send email.
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])
    except Exception, e:
        log.info("*** couldn't send join email")
        log.error(e)
        return False
Beispiel #12
0
def emailIdeaConfirmation(email, responseEmail, locationId):
    """
    Email upon idea submission.  Using template: idea_confirmation
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    host = Config.get('default_host')
    subject = "Thanks for submitting an idea to Change by Us!"
    searchLink = "%ssearch?location_id=%s" % (host, locationId)
    createLink = "%screate" % host
    template_values = {
        'search_link': searchLink,
        'create_link': createLink,
        'response_email': emailAccount['from_email'],
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/idea_confirmation', template_values, suffix = 'txt')

    # Send email.
    try:
        return Emailer.send(email, subject, body, from_name = emailAccount['from_name'],
            from_address = emailAccount['from_email'])
    except Exception, e:
        log.info("*** couldn't send authenticate user email")
        log.error(e)
        return False
Beispiel #13
0
def emailInvite(email, inviterName, projectId, title, description, message = None):
    """
    Send invitation email.  Using template: project_invite
        
    @type   email: string
    @param  email: Email address to send to
    ...
    
    @rtype: Boolean
    @returns: Whether emailer was successful or not.
    
    """
    
    # Create values for template.
    emailAccount = Config.get('email')
    subject = "You've been invited by %s to join a project" % inviterName
    link = "%sproject/%s" % (Config.get('default_host'), str(projectId))
    template_values = {
        'inviter': inviterName,
        'title':title,
        'description':description,
        'link': link,
        'message': message,
        'config': Config.get_all()
    }
    
    # Render email body.
    body = Emailer.render('email/project_invite', template_values, suffix = 'txt')     
    
    # Send email.
    try:
        return Emailer.send(email, subject,  body, from_name = emailAccount['from_name'], 
            from_address = emailAccount['from_email'])  
    except Exception, e:
        log.info("*** couldn't send invite email")
        log.error(e)
        return False
Beispiel #14
0
    def createDigests(self, store_to_db=True, mark=None):
        """ Create the digests based on FromDate and ToDate """
        if self.FromDate is None or self.ToDate is None:
            if mark is None:
                logging.error(
                    "Cannot proceed since there's no time range to get the digests for!"
                )
                return False
            else:
                # Set the date range to yesterday
                # TODO: This really should be a lot more configurable!
                td = datetime.date(mark)
                fd = td + relativedelta(days=-1)
                self.FromDate = str(fd)
                self.ToDate = str(td)
                logging.info('Getting digests for date range: %s to %s' %
                             (fd, td))

        resp = self.getDataToCreateDigest()
        base_url = self.Config.get('default_host')
        member_profile_url = "%suseraccount/" % base_url
        digests = {}
        for projId in resp.keys():
            # Ignore all empty projects, and projects that have no recipients
            if ((resp[projId].get('members') is None or len(resp[projId].get('members')) == 0) and\
                (resp[projId].get('messages') is None or len(resp[projId].get('messages')) == 0)) or\
                resp[projId].get('recipients') is None or len(resp[projId].get('recipients')) == 0:
                continue

            # Initialize the digest data structure
            if digests.get(projId) is None:
                digests[projId] = {
                    'members': [],
                    'messages': [],
                    'recipients': ""
                }

            digests[projId]['recipients'] = resp[projId].get('recipients')
            digests[projId]['title'] = resp[projId].get('title')
            digests[projId]['project_id'] = projId
            digests[projId]['num_members'] = resp[projId].get('num_members')
            digests[projId]['link'] = "<a href='%sproject/%s'>%s</a>" % (
                self.Config.get('default_host'), projId,
                resp[projId].get('title'))

            if resp[projId].get('members') is not None and len(
                    resp[projId].get('members')) > 0:
                digests[projId]['members'] = resp[projId].get('members')

            if resp[projId].get('messages') is not None and len(
                    resp[projId].get('messages')) > 0:
                digests[projId]['messages'] = resp[projId].get('messages')

        # Store the formatted body
        for digest in digests:
            currentDigest = digests.get(digest)
            currentDigest['subject'] = "%s%s\n\n" % (
                self.Config.get('email').get('digest').get(
                    'digest_subject_prefix'), currentDigest.get('title'))
            currentDigest['body'] = Emailer.render(
                'email/digest', {
                    'digest': currentDigest,
                    'baseUrl': base_url,
                    'contactEmail': self.Config.get('email').get('from_email')
                })

        # Store it for later consumption
        logging.info('Created digests (in DB) for %s projects' %
                     len(digests.keys()))
        self.Digests = digests
        return True