Example #1
0
def queue_enquiry_simple():
    queue_mail_message(
        create_enquiry(),
        ['*****@*****.**',],
        'England vs India',
        'Who will win the series?',
    )
Example #2
0
 def form_valid(self, form):
     selection = form.cleaned_data['send_email']
     use_template = selection == 'template'
     with transaction.atomic():
         result = super().form_valid(form)
         if use_template:
             context = {
                 self.object.email: {
                     "SUBJECT": "Re: " + self.object.subject,
                     "BODY": self.object.description,
                     "DATE": self.object.created.strftime("%d-%b-%Y %H:%M:%S"),
                 },
             }
             queue_mail_template(
                 self.object,
                 'enquiry_acknowledgement',
                 context,
             )
         else:
             attachments = []
             if self.object.document:
                 attachments.append(self.object.document.file.name)
             queue_mail_message(
                 self.object,
                 [self.object.email],
                 self.object.subject,
                 self.object.description,
                 attachments=attachments,
             )
         transaction.on_commit(lambda: process_mail.delay())
         return result
Example #3
0
def mail_time_summary():
    users = []
    for item in InvoiceUser.objects.all():
        if item.mail_time_summary and item.user.email:
            users.append(item.user)
    for user in users:
        logger.info('mail_time_summary: {}'.format(user.username))
        report = time_summary(user, days=1)
        message = ''
        for d, summary in report.items():
            message = message + '\n\n{}, total time {}'.format(
                d.strftime('%d/%m/%Y %A'),
                summary['format_total'],
            )
            for ticket in summary['tickets']:
                message = message + '\n{}: {}, {} ({})'.format(
                    ticket['pk'],
                    ticket['contact'],
                    ticket['description'],
                    ticket['format_minutes'],
                )
        queue_mail_message(
            user,
            [user.email],
            'Time Summary for {}'.format(timezone.now().strftime('%d/%m/%Y')),
            message,
        )
    if users:
        process_mail.delay()
Example #4
0
def mail_time_summary():
    users = []
    for item in InvoiceUser.objects.all():
        if item.mail_time_summary and item.user.email:
            users.append(item.user)
    for user in users:
        logger.info('mail_time_summary: {}'.format(user.username))
        report = time_summary(user, days=1)
        message = ''
        for d, summary in report.items():
            message = message + '\n\n{}, total time {}'.format(
                d.strftime('%d/%m/%Y %A'),
                summary['format_total'],
            )
            for ticket in summary['tickets']:
                message = message + '\n{}: {}, {} ({})'.format(
                    ticket['pk'],
                    ticket['contact'],
                    ticket['description'],
                    ticket['format_minutes'],
                )
        queue_mail_message(
            user,
            [user.email],
            'Time Summary for {}'.format(timezone.now().strftime('%d/%m/%Y')),
            message,
        )
    if users:
        process_mail.delay()
Example #5
0
File: views.py Project: pkimber/pay
def _send_notification_email(payment, request):
    email_addresses = [n.email for n in Notify.objects.all()]
    if email_addresses:
        subject, message = payment.mail_subject_and_message(request)
        queue_mail_message(
            payment,
            email_addresses,
            subject,
            message,
        )
    else:
        logging.error(
            "Cannot send email notification of payment.  "
            "No email addresses set-up in 'enquiry.models.Notify'"
        )
Example #6
0
def test_queue_no_email():
    email_address = get_env_variable('TEST_EMAIL_ADDRESS_1')
    enquiry = make_enquiry(
        email_address,
        "Farming",
        'How many cows in the field?',
    )
    with pytest.raises(MailError) as e:
        queue_mail_message(
            enquiry,
            [],
            enquiry.subject,
            enquiry.description,
        )
    expect = "Cannot 'queue_mail_message' without 'email_addresses'"
    assert expect in str(e.value)
Example #7
0
def _queue_enquiry(attachments=None):
    if not attachments:
        attachments = []
    email_address = get_env_variable('TEST_EMAIL_ADDRESS_1')
    enquiry = make_enquiry(
        email_address,
        "Farming",
        'How many cows in the field?',
    )
    queue_mail_message(
        enquiry,
        [enquiry.email, ],
        enquiry.subject,
        enquiry.description,
        attachments=attachments,
    )
    return enquiry
Example #8
0
 def save(self, commit=True):
     instance = super(EnquiryForm, self).save(commit)
     if commit:
         email_addresses = [n.email for n in Notify.objects.all()]
         if email_addresses:
             queue_mail_message(
                 instance,
                 email_addresses,
                 'Enquiry from {}'.format(instance.name),
                 self._email_message(instance),
             )
             process_mail.delay()
         else:
             logging.error(
                 "Enquiry app cannot send email notifications.  "
                 "No email addresses set-up in 'mail.models.Notify'"
             )
     return instance
Example #9
0
 def save(self, **kwargs):
     result = super().save(**kwargs)
     email = self.cleaned_data["email"]
     body = ['email address: {}'.format(email)]
     active_users = get_user_model().objects.filter(email__iexact=email)
     if active_users:
         for user in active_users:
             body.append("  User name: {}".format(user.username))
             if user.is_active and user.has_usable_password():
                 body.append(
                     "  - Password reset email sent.  "
                     "(user is active and has a usable password)."
                 )
             else:
                 body.append(
                     "  - Password reset email has NOT been sent.  "
                 )
                 if not user.is_active:
                     body.append("  - (user is NOT active).")
                 if not user.has_usable_password():
                     body.append(
                         "  - (user does NOT have a usable password)."
                     )
     else:
         body.append(
             "There are no users on the system with this email address."
         )
     email_addresses = [n.email for n in Notify.objects.all()]
     if email_addresses:
         queue_mail_message(
             PasswordResetAudit.objects.audit(email),
             email_addresses,
             "Password reset request from {}".format(email),
             '\n'.join(body),
         )
         transaction.on_commit(lambda: process_mail.delay())
     else:
         logging.error(
             "Cannot send email notification of password request.  "
             "No email addresses set-up in 'mail.models.Notify'"
         )
     return result
Example #10
0
    def notify(self, request=None):
        """Send notification of checkout status.

        Pass in a 'request' if you want the email to contain the URL of the
        checkout transaction.

        """
        email_addresses = [n.email for n in Notify.objects.all()]
        if email_addresses:
            caption = self.action.name
            state = self.state.name
            subject = '{} - {} from {}'.format(
                state.upper(),
                caption.capitalize(),
                self.content_object.checkout_name,
            )
            message = '{} - {} - {} from {}, {}:'.format(
                self.created.strftime('%d/%m/%Y %H:%M'),
                state.upper(),
                caption,
                self.content_object.checkout_name,
                self.content_object.checkout_email,
            )
            message = message + '\n\n{}\n\n{}'.format(
                self.description,
                request.build_absolute_uri(self.content_object_url) if request else '',
            )
            queue_mail_message(
                self,
                email_addresses,
                subject,
                message,
            )
        else:
            logger.error(
                "Cannot send email notification of checkout transaction.  "
                "No email addresses set-up in 'enquiry.models.Notify'"
            )