Beispiel #1
0
    def test_EmailMessage_attributes(self):
        """Test that send_at and categories attributes are correctly written through to output."""
        msg = EmailMessage(
            subject="Hello, World!",
            body="Hello, World!",
            from_email="Sam Smith <*****@*****.**>",
            to=["John Doe <*****@*****.**>", "*****@*****.**"],
        )

        # Set new attributes as message property
        msg.send_at = 1518108670
        if SENDGRID_VERSION < '6':
            msg.categories = ['mammal', 'dog']
        else:
            msg.categories = ['dog', 'mammal']

        msg.ip_pool_name = 'some-name'

        result = self.backend._build_sg_mail(msg)
        expected = {
            "personalizations": [{
                "to": [{
                    "email": "*****@*****.**",
                    "name": "John Doe"
                }, {
                    "email": "*****@*****.**",
                }],
                "subject":
                "Hello, World!",
                "send_at":
                1518108670,
            }],
            "from": {
                "email": "*****@*****.**",
                "name": "Sam Smith"
            },
            "mail_settings": {
                "sandbox_mode": {
                    "enable": False
                }
            },
            "subject":
            "Hello, World!",
            "tracking_settings": {
                "open_tracking": {
                    "enable": True
                }
            },
            "content": [{
                "type": "text/plain",
                "value": "Hello, World!"
            }],
            "categories": ['mammal', 'dog'],
            "ip_pool_name":
            "some-name"
        }

        self.assertDictEqual(result, expected)
Beispiel #2
0
def send_pud(pud):
    email = EmailMessage(to=[pud.author.email])
    email.template_name = 'pud'
    email.global_merge_vars = {
        'content': pud.content,
        'priority': pud.priority
    }

    email.send_at = pud.created_at + datetime.timedelta(days=pud.notify_when)

    email.use_template_subject = True
    email.use_template_from = False
    email.send(fail_silently=False)

    if pud.need_repeat:
        if pud.repeat == 'Daily':
            email.send_at = email.send_at + datetime.timedelta(days=1)
        elif pud.repeat == 'Weekly':
            email.send_at = email.send_at + datetime.timedelta(weeks=1)
        email.send(fail_silently=False)

    response = email.mandrill_response[0]
    print response
    return response
Beispiel #3
0
def send_pud(pud):
    email = EmailMessage(to=[pud.author.email])
    email.template_name = 'pud'
    email.global_merge_vars = {
        'content': pud.content,
        'priority': pud.priority
    }

    email.send_at = pud.created_at + datetime.timedelta(days=pud.notify_when)

    email.use_template_subject = True
    email.use_template_from = False
    email.send(fail_silently=False)

    if pud.need_repeat:
        if pud.repeat == 'Daily':
            email.send_at = email.send_at + datetime.timedelta(days=1)
        elif pud.repeat == 'Weekly':
            email.send_at = email.send_at + datetime.timedelta(weeks=1)
        email.send(fail_silently=False)

    response = email.mandrill_response[0]
    print response
    return response
    def test_EmailMessage_attributes(self):
        """Test that send_at and categories attributes are correctly written through to output."""
        msg = EmailMessage(
            subject="Hello, World!",
            body="Hello, World!",
            from_email="Sam Smith <*****@*****.**>",
            to=["John Doe <*****@*****.**>", "*****@*****.**"],
        )

        # Set new attributes as message property
        msg.send_at = 1518108670
        msg.categories = ['mammal', 'dog']
        msg.ip_pool_name = 'some-name'

        result = self.backend._build_sg_mail(msg)
        expected = {
            "personalizations": [{
                "to": [{
                    "email": "*****@*****.**",
                    "name": "John Doe"
                }, {
                    "email": "*****@*****.**",
                }],
                "subject": "Hello, World!",
                "send_at": 1518108670,
            }],
            "from": {
                "email": "*****@*****.**",
                "name": "Sam Smith"
            },
            "mail_settings": {
                "sandbox_mode": {
                    "enable": False
                }
            },
            "subject": "Hello, World!",
            "tracking_settings": {"open_tracking": {"enable": True}},
            "content": [{
                "type": "text/plain",
                "value": "Hello, World!"
            }],
            "categories": ['mammal', 'dog'],
            "ip_pool_name": "some-name"
        }

        self.assertDictEqual(result, expected)
Beispiel #5
0
def send_post(post):
    when = post.day_of_week + ', ' + post.show_date
    if post.not_all_day:
        when = when + ' at ' + post.show_begin_time
    email = EmailMessage(to=[post.author.email])
    email.template_name = 'post'
    email.global_merge_vars = {
        'content': post.content,
        'description': post.description_event,
        'location': post.location_event,
        'when': when
    }
    email.send_at = post.notify_when
    email.use_template_subject = True
    email.use_template_from = False
    email.send(fail_silently=False)

    response = email.mandrill_response[0]
    print response
    return response
Beispiel #6
0
    def send_delayed_welcome_email(self):
        site = Site.objects.get_current()

        subject = site.name
        message = '''Salaam,

I'm Sikander, the creator of %s. Thanks for signing up! I wanted to reach out to see if you needed any help getting started.

Best,

--
Sikander Chowhan
www.%s''' % (site.name, site.domain)

        from_email = 'Sikander Chowhan <sikander@%s>' % site.domain
        to = [self.user.email]

        email = EmailMessage(subject, message, from_email, to)
        email.send_at = datetime.now() + timedelta(days=1)
        email.send()
Beispiel #7
0
def send_post(post):
    when = post.day_of_week + ', ' + post.show_date
    if post.not_all_day:
        when = when + ' at ' + post.show_begin_time
    email = EmailMessage(to=[post.author.email])
    email.template_name = 'post'
    email.global_merge_vars = {
        'content': post.content,
        'description': post.description_event,
        'location': post.location_event,
        'when': when
    }
    email.send_at = post.notify_when
    email.use_template_subject = True
    email.use_template_from = False
    email.send(fail_silently=False)

    response = email.mandrill_response[0]
    print response
    return response
Beispiel #8
0
    def send_delayed_welcome_email(self):
        site = Site.objects.get_current()

        subject = site.name
        message = '''Salaam,

I'm Sikander, the creator of %s. Thanks for signing up! I wanted to reach out to see if you needed any help getting started.

Best,

--
Sikander Chowhan
www.%s''' % (site.name, site.domain)

        from_email = 'Sikander Chowhan <sikander@%s>' % site.domain
        to = [self.user.email]

        email = EmailMessage(subject, message, from_email, to)
        email.send_at = datetime.now() + timedelta(days=1)
        email.send()