Esempio n. 1
0
 def send(self, confirmation_email):
     if not self.cm_id:
         raise ValueError("No draft created yet")
     campaign = CSCampaign(auth=settings.CREDENTIALS, campaign_id=self.cm_id)
     campaign.send(confirmation_email=confirmation_email)
     self.status = self.STATUS_SENT
     self.save()
Esempio n. 2
0
 def send(self, confirmation_email):
     if not self.cm_id:
         raise ValueError("No draft created yet")
     campaign = CSCampaign(auth=settings.CREDENTIALS, campaign_id=self.cm_id)
     campaign.send(confirmation_email=confirmation_email)
     self.status = self.STATUS_SENT
     self.save()
Esempio n. 3
0
    def reset_send_email(self, article_id):
        try:
            parser = HTMLParser.HTMLParser()
            resp = 'failed'
            page = self.base_campaign.read_page(article_id)
            article_asset, md, sd = page.get_asset()

            news_article_datetime = datetime.datetime.fromtimestamp(int(find(sd, 'publish-date', False))/1000)
            current_datetime = datetime.datetime.now()

            # ignore any that are on a different day, or in _testing
            if news_article_datetime.strftime("%m-%d-%Y") != current_datetime.strftime("%m-%d-%Y") or '_testing/' in find(article_asset, 'path', False):
                return "Don't need to send"

            # add news_article
            news_article_text = self.base_campaign.create_single_news_article(article_asset, news_article_datetime)
            news_article_title = parser.unescape(find(md, 'title', False))

            if news_article_text != '':
                campaign_monitor_key = app.config['NEWS_CAMPAIGN_MONITOR_KEY']
                CreateSend({'api_key': campaign_monitor_key})
                new_campaign = Campaign({'api_key': campaign_monitor_key})

                client_id = app.config['NEWS_CLIENT_ID']
                subject = news_article_title + ' | Bethel News'
                name = '%s | %s' % (news_article_title, str(current_datetime.strftime('%m/%-d/%Y')))
                from_name = 'Bethel News'
                from_email = '*****@*****.**'
                reply_to = '*****@*****.**'
                list_ids = [app.config['NEWS_LIST_KEY']]
                segment_ids = [app.config['NEWS_SEGMENT_ID']]
                template_id = app.config['NEWS_TEMPLATE_ID']
                template_content = {
                    "Singlelines": [
                        {
                            "Content": "<p>%s</p>" % news_article_text
                        }
                    ]
                }

                send_email_value = find(sd, 'send-email', False)

                if app.config['ENVIRON'] == 'prod' and send_email_value == 'Yes':
                    self.base_campaign.reset_send_email_value(page)

                    resp = new_campaign.create_from_template(client_id, subject, name, from_name, from_email, reply_to,
                                                             list_ids,
                                                             segment_ids, template_id, template_content)

                    now = datetime.datetime.now()
                    now_plus_10 = now + datetime.timedelta(minutes=10)

                    confirmation_email_sent_to = ', '.join(app.config['ADMINS'])
                    new_campaign.send(confirmation_email_sent_to, str(now_plus_10.strftime('%Y-%m-%d %H:%M')))
                    self.base_campaign.log_sentry("News campaign created", resp)

        except:
            return 'failed'

        return resp
 def send(self, confirmation_email):
     if not self.cm_id:
         raise ValueError("No draft created yet")
     CreateSend.api_key = settings.API_KEY
     campaign = CSCampaign(self.cm_id)
     campaign.send(confirmation_email=confirmation_email)
     self.status = self.STATUS_SENT
     self.save()
 def send(self, confirmation_email):
     if not self.cm_id:
         raise ValueError("No draft created yet")
     CreateSend.api_key = settings.API_KEY
     campaign = CSCampaign(self.cm_id)
     campaign.send(confirmation_email=confirmation_email)
     self.status = self.STATUS_SENT
     self.save()
Esempio n. 6
0
 def create_draft(self, preview_recipients=[]):
     campaign = CSCampaign(auth=settings.CREDENTIALS)
     attrs = dict(
         client_id=settings.CLIENT_ID,
         subject=self.subject,
         name=self.name,
         from_name=self.from_name,
         from_email=self.from_email,
         reply_to=self.from_email, # TODO
         html_url=self.html_url,
         text_url=self.text_url,
         list_ids=self.list_ids,
         segment_ids=self.segment_ids,
     )
     try:
         campaign_id = campaign.create(**attrs)
         self.cm_id = campaign_id
         self.status = self.STATUS_DRAFT
         self.save()
     except BadRequest, e:
         raise
 def create_draft(self, preview_recipients=[]):
     CreateSend.api_key = settings.API_KEY
     campaign = CSCampaign()
     attrs = dict(
         client_id=settings.CLIENT_ID,
         subject=self.subject,
         name=self.name,
         from_name=self.from_name,
         from_email=self.from_email,
         reply_to=self.from_email,  # TODO
         html_url=self.html_url,
         text_url=self.text_url,
         list_ids=self.list_ids,
         segment_ids=self.segment_ids,
     )
     try:
         campaign_id = campaign.create(**attrs)
         self.cm_id = campaign_id
         self.status = self.STATUS_DRAFT
         self.save()
     except BadRequest, e:
         raise
Esempio n. 8
0
 def create_draft(self, preview_recipients=[]):
     campaign = CSCampaign(auth=settings.CREDENTIALS)
     attrs = dict(
         client_id=settings.CLIENT_ID,
         subject=self.subject,
         name=self.name,
         from_name=self.from_name,
         from_email=self.from_email,
         reply_to=self.from_email, # TODO
         html_url=self.html_url,
         text_url=self.text_url,
         list_ids=self.list_ids,
         segment_ids=self.segment_ids,
     )
     try:
         campaign_id = campaign.create(**attrs)
         self.cm_id = campaign_id
         self.status = self.STATUS_DRAFT
         self.save()
     except BadRequest as e:
         raise
     if len(preview_recipients):
         campaign = CSCampaign(auth=settings.CREDENTIALS, campaign_id=campaign_id)
         campaign.send_preview(preview_recipients)
Esempio n. 9
0
    def send(self):
        if getattr(settings, 'DRIP_USE_CREATESEND', False):

            template_name = self.drip_model.template_name
            segment_name = 'Drip Segment %s' % self.drip_model.name.replace("'",'').replace('"','')
            from createsend import Campaign, Segment,  CreateSend, BadRequest, Client

            CreateSend.api_key = settings.CREATESEND_API

            client = Client(settings.CREATESEND_CLIENT_ID)

            template_id = None
            for template in client.templates():
                if template.Name == template_name:
                    template_id = template.TemplateID

            if template_id is None:
                raise Exception("Template with the name '%s' does not exist" % template_name)

            segment_id = None
            for segment in client.segments():
                if segment.Title == segment_name and segment.ListID == settings.CREATESEND_LIST_ID:
                    segment_id = segment.SegmentID

            rules = []
            count = 0

            qs = self.get_queryset()
            clauses = []

            for user in qs:
                clauses.append("EQUALS %s" % user.email)
                count += 1
            rules = [{
                    
                    'Subject' : 'EmailAddress',
                    'Clauses' : clauses,
                    }]


            if count:
                if segment_id is not None:
                    segment = Segment(segment_id)
                    segment.clear_rules()
                    segment.update(segment_name, rules)
                else:
                    segment_id = Segment().create(settings.CREATESEND_LIST_ID, segment_name, rules)
                    segment = Segment(segment_id)

                subject = Template(self.subject_template).render(Context())
                body = Template(self.body_template).render(Context())
                name    = 'Drip Campaign %s %s' % (self.drip_model.name, datetime.now().isoformat())

                from_address = getattr(settings, 'DRIP_FROM_EMAIL', settings.EMAIL_HOST_USER)

                template_content = {
                    "Multilines" : [{
                        'Content': body,
                        },],
                    }


                campaign_id = Campaign().create_from_template(settings.CREATESEND_CLIENT_ID, 
                                                              subject, 
                                                              name, 
                                                              from_address, 
                                                              from_address, 
                                                              from_address, 
                                                              [], 
                                                              [segment.details().SegmentID], 
                                                              template_id, 
                                                              template_content,
                                                              )
                campaign = Campaign(campaign_id)
                failed = False
                try:
                    campaign.send(settings.CREATESEND_CONFIRMATION_EMAIL)
                except BadRequest as br:
                    print "ERROR: Could not send Drip %s: %s" % (self.drip_model.name, br)
                    failed = True
                
                if not failed:
                    for user in qs:
                        sd = SentDrip.objects.create(
                            drip=self.drip_model,
                            user=user,
                            subject=subject,
                            body=body
                            )

            return count

            

        else:
            """
            Send the email to each user on the queryset.

            Add that user to the SentDrip.

            Returns a list of created SentDrips.
            """

            count = 0
            for user in self.get_queryset():
                msg = self.build_email(user, send=True)
                count += 1

            return count