def send(self, template_name, from_email, recipient_list, context, cc=None,
            bcc=None, fail_silently=False, headers=None, template_prefix=None,
            template_suffix=None, template_dir=None, file_extension=None,
            **kwargs):

        msg = EmailMessage(from_email=from_email, to=recipient_list)
        msg.template_name = template_name
        msg.global_merge_vars = context
        msg.fail_silently = fail_silently

        if cc:
            msg.cc = cc
        if bcc:
            msg.bcc = bcc

        msg.use_template_subject = kwargs.get('use_template_subject', True)
        msg.use_template_from = kwargs.get('use_template_from', True)
        msg.async = kwargs.get('async', True)

        try:
            msg.send()
        except Exception as e:
            if not fail_silently:
                raise
        return msg.extra_headers.get('Message-Id', None)
def send_custom_email_mandrill(email_to, temp_vars):
    msg = EmailMessage(to=[email_to])
    msg.template_name = "test-email"  # slug from Mandrill
    msg.global_merge_vars = temp_vars
    msg.use_template_subject = True
    msg.use_template_from = True
    msg.send()
def send_mandrill_template_mail(
    template_name,
    to,
    global_merge_vars=None,
    merge_vars=None,
    content_blocks=None,
    subject=None,
    from_email=None,
    **options
):
    if isinstance(to, six.string_types):
        to = [to]
    msg = EmailMessage(subject=subject, from_email=from_email, to=to)
    msg.template_name = template_name
    if content_blocks:
        msg.template_content = content_blocks
    if global_merge_vars:
        msg.global_merge_vars = global_merge_vars
    if merge_vars:
        msg.merge_vars = merge_vars
    for option, value in six.iteritems(options):
        if option not in VALID_DJRILL_OPTIONS:
            raise ValueError("Invalid option for Mandrill template: %s" % option)
        setattr(msg, option, value)
    if not subject:
        msg.use_template_subject = True
    if not from_email:
        msg.use_template_from = True
    msg.send()
Beispiel #4
0
def send_mandrill_template_mail(template_name,
                                to,
                                global_merge_vars=None,
                                merge_vars=None,
                                content_blocks=None,
                                subject=None,
                                from_email=None,
                                **options):
    if isinstance(to, six.string_types):
        to = [to]
    msg = EmailMessage(subject=subject, from_email=from_email, to=to)
    msg.template_name = template_name
    if content_blocks:
        msg.template_content = content_blocks
    if global_merge_vars:
        msg.global_merge_vars = global_merge_vars
    if merge_vars:
        msg.merge_vars = merge_vars
    for option, value in six.iteritems(options):
        if option not in VALID_DJRILL_OPTIONS:
            raise ValueError('Invalid option for Mandrill template: %s' %
                             option)
        setattr(msg, option, value)
    if not subject:
        msg.use_template_subject = True
    if not from_email:
        msg.use_template_from = True
    msg.send()
Beispiel #5
0
 def render_djrill_mail(self, template, email, ctx):
     """
     Renders an e-mail using mandrill template.
     """
     msg = EmailMessage(from_email=settings.DEFAULT_FROM_EMAIL, to=[email])
     msg.template_name = template
     msg.merge_vars = {email: ctx}
     msg.use_template_subject = True
     msg.use_template_from = True
     return msg
Beispiel #6
0
def send_email_template(request):
    """
    Send an email with mandrill template
    ---
    parameters:
        - name: FromEmail
          description: This is from email address field
        - name: ToRecipients
          description: This is from email address field
        - name: Subject
          description: This is from email address field
        - name: TemplateName
          description: This is from email address field
        - name: TemplateContent
          description: This is from email address field
        - name: UseTemplateSubject
          description: This is from email address field
        - name: UseTemplateFrom
          description: This is from email address field

    """

    request_content = request.body

    request_body = json.loads(request_content)

    from_email = request_body.get("FromEmail", "")
    to_recipients = request_body.get("ToRecipients")
    subject = request_body.get("Subject", "")
    template_name = request_body.get("TemplateName")
    template_content = request_body.get("TemplateContent")
    use_template_subject = request_body.get("UseTemplateSubject", False)
    use_template_from = request_body.get("UseTemplateFrom", False)

    msg = EmailMessage(subject=subject,
                       from_email=from_email,
                       to=to_recipients)

    msg.template_name = template_name
    msg.template_content = template_content
    msg.use_template_subject = use_template_subject
    msg.use_template_from = use_template_from

    try:
        msg.send()

        response = {"Message": 'Your email has been sent.'}

        return HttpResponse(json.dumps(response),
                            content_type='application/json')

    except Exception as ex:
        return server_error(ex)
Beispiel #7
0
 def post(self, request):
     from_email = request.DATA['fromEmail']
     from_name = request.DATA['fromName']
     to_email = request.DATA['toEmail']
     to_name = request.DATA['toName']
     email = EmailMessage(to=[to_email], from_email=from_email)
     email.template_name = "send-to-friend"
     email.global_merge_vars = {'FROMFRIEND': from_name, \
         'TOFRIEND': to_name}
     email.use_template_subject = True
     email.send()
     return HttpResponse(status=status.HTTP_204_NO_CONTENT)
def send_email_template(request):
    """
    Send an email with mandrill template
    ---
    parameters:
        - name: FromEmail
          description: This is from email address field
        - name: ToRecipients
          description: This is from email address field
        - name: Subject
          description: This is from email address field
        - name: TemplateName
          description: This is from email address field
        - name: TemplateContent
          description: This is from email address field
        - name: UseTemplateSubject
          description: This is from email address field
        - name: UseTemplateFrom
          description: This is from email address field

    """

    request_content = request.body

    request_body = json.loads(request_content)

    from_email = request_body.get("FromEmail", "")
    to_recipients = request_body.get("ToRecipients")
    subject = request_body.get("Subject", "")
    template_name = request_body.get("TemplateName")
    template_content = request_body.get("TemplateContent")
    use_template_subject = request_body.get("UseTemplateSubject", False)
    use_template_from = request_body.get("UseTemplateFrom", False)

    msg = EmailMessage(subject=subject, from_email=from_email, to=to_recipients)

    msg.template_name = template_name
    msg.template_content = template_content
    msg.use_template_subject = use_template_subject
    msg.use_template_from = use_template_from

    try:
        msg.send()

        response = { "Message": 'Your email has been sent.' }

        return HttpResponse(json.dumps(response), content_type='application/json')

    except Exception as ex:
        return server_error(ex)
Beispiel #9
0
 def post(self, request):
     from_email = request.DATA['fromEmail']
     from_name = request.DATA['fromName']
     to_email = request.DATA['toEmail']
     to_name = request.DATA['toName']
     email = EmailMessage(
         to=[to_email],
         from_email=from_email
     )
     email.template_name = "send-to-friend"
     email.global_merge_vars = {'FROMFRIEND': from_name, \
         'TOFRIEND': to_name}
     email.use_template_subject = True
     email.send()
     return HttpResponse(status=status.HTTP_204_NO_CONTENT)
Beispiel #10
0
def sendSystemEmail(user, subject, template_name, merge_vars):

    merge_vars["first_name"] = user.first_name
    merge_vars["last_name"] = user.last_name
    merge_vars["site_url"] = settings.SITE_URL
    merge_vars["current_year"] = timezone.now().year
    merge_vars["company"] = "CoderDojoChi"

    msg = EmailMessage(subject=subject, from_email=settings.DEFAULT_FROM_EMAIL, to=[user.email])

    msg.template_name = template_name
    msg.global_merge_vars = merge_vars
    msg.inline_css = True
    msg.use_template_subject = True
    msg.send()
Beispiel #11
0
 def save(self, *args, **kwargs):
     """
     Sends confirmation email about appointment
     """
     super(Appointment, self).save(*args, **kwargs)
     email = EmailMessage(
         to=[self.participant.email]
     )
     email.template_name = "appointment-email"
     email.global_merge_vars = {'TEST': self.test.title, \
         'DATE': self.date.__format__('%A, %B %-d, %Y'), \
         'TIME': self.time.__format__('%-I:%M %p')}
     email.use_template_subject = True
     email.use_template_from = True
     email.send()
Beispiel #12
0
def send_welcome_mail(sender, email_address, **kwargs):
    user = email_address.user
    emailId = user.first_name + " " + user.last_name + "<" +\
        email_address.email + ">"
    msg = EmailMessage(subject="Welcome to Makeystreet",
                       from_email="Alex J V<*****@*****.**>",
                       to=[emailId],
                       cc=['Numaan Ashraf<*****@*****.**>'],
                       bcc=['Alex JV<*****@*****.**>'])
    msg.template_name = "SignUp"
    msg.use_template_subject = True
    msg.use_template_from = True
    msg.global_merge_vars = {
        'USERNAME': user.first_name,
    }
    msg.preserve_recipients = True
    msg.send()
Beispiel #13
0
def sendSystemEmail(user, subject, template_name, merge_vars):

    merge_vars['first_name'] = user.first_name
    merge_vars['last_name'] = user.last_name
    merge_vars['site_url'] = settings.SITE_URL
    merge_vars['current_year'] = timezone.now().year
    merge_vars['company'] = 'CoderDojoChi'

    msg = EmailMessage(subject=subject,
                       from_email=settings.DEFAULT_FROM_EMAIL,
                       to=[user.email])

    msg.template_name = template_name
    msg.global_merge_vars = merge_vars
    msg.inline_css = True
    msg.use_template_subject = True
    msg.send()
Beispiel #14
0
    def email_user(self, subject, from_email=None, **kwargs):
        """
        Sends an email to this User.
        """

        email = EmailMessage(to=[self.email], from_email=from_email)

        email.template_name = "forgot-password"
        email.use_template_subject = True
        email.use_template_from = True

        email.global_merge_vars = {
            "SITE_NAME": Site.objects.get_current().name,
            "RESET_TOKEN": self.password_reset_token
        }

        email.send(fail_silently=False)
Beispiel #15
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 #16
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 #17
0
 def save(self, *args, **kwargs):
     """
     Override of save to make sure hash is created with ID
     Sends email once this is done
     """
     super(FormAPI, self).save(*args, **kwargs)
     if self.hashInit == '':
         hasher = hashlib.sha512()
         hasher.update(self.createHASH())
         self.hashInit = hasher.hexdigest()
         formapi = FormAPI.objects.get(pk = self.id)
         formapi.hashInit = self.hashInit
         formapi.save()
         email = EmailMessage(
             to=[self.email]
         )
         email.template_name = "confirmation email"
         link = self.hashInit
         email.global_merge_vars = {'URL': link}
         email.use_template_subject = True
         email.use_template_from = True
         email.send()
Beispiel #18
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 #19
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