コード例 #1
0
ファイル: mail.py プロジェクト: alberthan92/mysite-project
def send_test():
    django_send_mail(
        'subject',
        'message.',
        settings.EMAIL_HOST_USER,
        ['*****@*****.**'],
    )
コード例 #2
0
def send_mail(recipient_list,
              subject,
              path_to_template,
              context={},
              fail_silently=True,
              sender=SERVER_EMAIL):
    """Send email.

    Args:
        recipient_list:
        subject:
        path_to_template:
        context:
        fail_silently:
        sender:

    Returns:

    """
    try:
        # Render the given template with context information
        template = loader.get_template(path_to_template)
        context = Context(context)
        message = template.render(context)
        # Send mail
        django_send_mail(subject=EMAIL_SUBJECT_PREFIX + subject,
                         message='',
                         from_email=sender,
                         recipient_list=recipient_list,
                         html_message=message,
                         fail_silently=fail_silently)
    except BadHeaderError, e:
        raise e
コード例 #3
0
def send_mail(title='', message='', sender=None, receivers=[], html=False):
    """Function for sending mails.

    If we are on debug (development) the email message will be sent by django
    mailer, otherwise we will use the mailgun api.

    """
    if not sender:
        sender = getattr(settings, 'EMAIL_SENDER',
                         'MootiroMaps <*****@*****.**>')

    if settings.DEBUG and not html:
        django_send_mail(title,
                         message,
                         sender,
                         receivers,
                         fail_silently=False)
    else:
        data = {
            'from': sender,
            'to': receivers,
            'subject': title,
        }
        if html:
            data['html'] = message
        else:
            data['text'] = message

        requests.post(settings.MAILGUN_API_URL,
                      auth=('api', settings.MAILGUN_API_KEY),
                      data=data)
コード例 #4
0
ファイル: helpers.py プロジェクト: stratopedarx/priceguru
def send_mail(subject, template_name, to, is_html=True, **kwargs):
    kwargs['settings'] = settings
    content = render_to_string(template_name, kwargs)

    django_send_mail(subject, content if not is_html else None,
                     settings.DEFAULT_FROM_EMAIL, [to],
                     html_message=content if is_html else None)
コード例 #5
0
def send_mail(subject,
              message,
              from_email,
              recipient_list,
              fail_silently=False,
              auth_user=None,
              auth_password=None,
              connection=None):
    '''
    Sends an email to the given recipients' user list in their language. Use
    ugettext_lazy if you want the email to be correctly translated.
    '''
    from django.utils import translation
    from django.core.mail import send_mail as django_send_mail

    cur_language = translation.get_language()
    default_language = settings.LANGUAGE_CODE
    try:
        for recipient in recipient_list:
            print "language code: ", recipient.lang_code, default_language
            if recipient.lang_code:
                translation.activate(recipient.lang_code)
            else:
                translation.activate(default_language)

            django_send_mail(unicode(subject), unicode(message), from_email, [
                recipient.email,
            ], fail_silently, auth_user, auth_password, connection)
    finally:
        translation.activate(cur_language)
コード例 #6
0
def send_mail(txt, subject, me, you):
    django_send_mail(
        from_email = settings.DEFAULT_FROM_EMAIL,
        subject = subject,
        recipient_list = [you],
        message = txt
    )
コード例 #7
0
def send_mail(request, instance):
    reserved_fields = ('_gotcha', '_next', '_subject')

    referrer = request.META.get('HTTP_REFERER', '')
    subject = request.POST.get(
        '_subject', _('New submission from {referrer}').format(referrer=referrer))
    from_email = request.POST.get('email', None)
    recipients = instance.get_recipients()

    form_data = OrderedDict()
    for field, value in six.iteritems(request.POST):
        if field not in reserved_fields:
            form_data[field] = value

    # prevent submitting empty form
    if not any(form_data.values()):
        raise EmptyFormError()

    context = {
        'form_data': form_data,
        'instance': instance,
        'referrer': referrer,
    }

    message = render_to_string('fwdform/submission.txt', context)

    try:
        django_send_mail(subject, message, from_email, recipients, fail_silently=False)
    except Exception as e:  # pragma: no cover
        logger.error(str(e))
        message = _('Oops! An error occurred and your message could not be sent.')
        raise FwdFormError(message)

    instance.sent_count = F('sent_count') + 1
    instance.save()
コード例 #8
0
    def post(self, request):
        errors = []
        required = [
            {
                'name': 'title',
                'error-message': 'Title field should not be empty.'
            },
            {
                'name': 'content',
                'error-message': 'Content field should not be empty.'
            },
            {
                'name': 'email',
                'error-message': 'Email field should not be empty.'
            },
        ]

        for r in required:
            if not request.POST[r['name']].strip():
                errors.append(r['error-message'])

        if len(errors) > 0:
            return render(request, "blog/contact.html", {
                "errors": errors,
            })

        django_send_mail(request.POST['title'], request.POST['content'],
                         request.POST['email'], ['*****@*****.**'])

        return redirect(reverse("blog:contact-success"))
コード例 #9
0
ファイル: mail.py プロジェクト: YongPilMoon/mysite
def send_test():
    django_send_mail(
        'Subject',
        'Message',
        settings.EMAIL_HOST_USER
        ['*****@*****.**']
    )
コード例 #10
0
def notify_me(purchase_pk):
    from products.models import ProductPurchase
    pp = ProductPurchase.objects.get(pk=purchase_pk)
    if not pp.notification_email_sent:
        product_name = pp.product.name
        if pp.purchase.person.first_name:
            person_name = "%s (%s)" % (pp.purchase.person.first_name,
                                       pp.purchase.person.email)
        else:
            person_name = pp.purchase.person.email
        if pp.purchase.help_edition:
            product_name = "%s (Help Edition)" % product_name

        body = """
    Hey there,

    Great news!  %s just bought the %s!

    Woo! 🎉🎉🎉

    Have a great day,

    -The helpful inkshop robots :)

    """ % (person_name, product_name)
        django_send_mail("💰 New Sale of %s!" % product_name,
                         body,
                         settings.INKSHOP_FROM_EMAIL, [
                             settings.INKSHOP_ADMIN_EMAIL,
                         ],
                         fail_silently=False)
        pp.notification_email_sent = True
        pp.save()
コード例 #11
0
ファイル: mail.py プロジェクト: Fastcampus-WPS/WPS-3rd
def send_test():
    django_send_mail(
        'Subject',
        'Message',
        settings.EMAIL_HOST_USER,
        ['*****@*****.**']
    )
コード例 #12
0
ファイル: mail.py プロジェクト: shoark7/WPS_mysite_project
def send_mail(subject, message, recipient_list=None):
    default_recipient_list = ['*****@*****.**']
    django_send_mail(subject=subject,
                     message=message,
                     from_email=settings.EMAIL_HOST_USER,
                     recipient_list=recipient_list
                     if recipient_list else default_recipient_list)
コード例 #13
0
ファイル: views.py プロジェクト: DataMining4Finance/Blitz-API
    def send_refund_confirmation_email(self, amount, retreat, order, user,
                                       total_amount, amount_tax):
        # Here the price takes the applied coupon into account, if
        # applicable.
        old_retreat = {
            'price': (amount * retreat.refund_rate) / 100,
            'name': "{0}: {1}".format(_("Retreat"), retreat.name)
        }

        # Send order confirmation email
        merge_data = {
            'DATETIME': timezone.localtime().strftime("%x %X"),
            'ORDER_ID': order.id,
            'CUSTOMER_NAME': user.first_name + " " + user.last_name,
            'CUSTOMER_EMAIL': user.email,
            'CUSTOMER_NUMBER': user.id,
            'TYPE': "Remboursement",
            'OLD_RETREAT': old_retreat,
            'COST': round(total_amount / 100, 2),
            'TAX': round(Decimal(amount_tax / 100), 2),
        }

        plain_msg = render_to_string("refund.txt", merge_data)
        msg_html = render_to_string("refund.html", merge_data)

        django_send_mail(
            "Confirmation de remboursement",
            plain_msg,
            settings.DEFAULT_FROM_EMAIL,
            [user.email],
            html_message=msg_html,
        )
コード例 #14
0
ファイル: mail.py プロジェクト: Fastcampus-WPS/WPS-3rd
def send_mail(subject, message, recipient_list=None):
    default_recipient_list = ['*****@*****.**']
    django_send_mail(subject=subject,
                     message=message,
                     from_email=settings.DEFAULT_FROM_EMAIL,
                     recipient_list=recipient_list
                     if recipient_list else default_recipient_list)
コード例 #15
0
ファイル: utils.py プロジェクト: acasimiro/mootiro-maps
def send_mail(title='', message='',
              sender='MootiroMaps <*****@*****.**>', receivers=[],
              html=False):
    '''
    function for sending mails. If we are on debug (development) se will be
    sent by django mailer else will use the mailgun api.
    mailer.
    '''
    if settings.DEBUG and not html:
        django_send_mail(title, message, sender, receivers,
                            fail_silently=False)
    else:
        data = {
            'from': 'MootiroMaps <*****@*****.**>',
            'to': receivers,
            'subject': title,
        }
        if html:
            data['html'] = message
        else:
            data['text'] = message

        requests.post(
            settings.MAILGUN_API_URL,
            auth=('api', settings.MAILGUN_API_KEY),
            data=data
        )
コード例 #16
0
def send_mail(product, subscription, price, additional_text=''):
    """
    Sends an email using the appropriate settings for formatting aso.

    :param product: the product
    :type product: price_monitor.models.Product
    :param subscription: the subscription
    :type subscription: price_monitor.models.Subscription
    :param price: the current price
    :type price: price_monitor.models.Price
    :param additional_text: additional text to include in mail
    :type additional_text: str
    """
    django_send_mail(
        _(app_settings.PRICE_MONITOR_I18N_EMAIL_NOTIFICATION_SUBJECT) % {'product': product.title},
        _(app_settings.PRICE_MONITOR_I18N_EMAIL_NOTIFICATION_BODY).format(
            price_limit=subscription.price_limit,
            currency=price.currency,
            price=price.value,
            price_date=price.date_seen.strftime('%b %d, %Y %H:%M %p %Z'),
            product_title=product.get_title(),
            url_product_amazon=product.offer_url,
            url_product_detail=product.get_detail_url(),
            additional_text=additional_text,
        ),
        app_settings.PRICE_MONITOR_EMAIL_SENDER,
        [subscription.email_notification.email],
        fail_silently=False,
    )
コード例 #17
0
def send_email(to_email,
               context,
               subject,
               plain_template,
               html_template,
               from_email=None):
    """
    Render a plain and html message based on a context and send it using django.core.mail.
    """

    plain_body = render_to_string(plain_template, context)

    html_body = None
    if html_template:
        html_body = render_to_string(html_template, context)

    recipient_list = to_email if isinstance(to_email, list) else [to_email]

    log.info(
        "send_mail",
        subject=subject,
        from_email=from_email,
        recipient_list=recipient_list,
    )

    django_send_mail(
        subject=subject,
        message=plain_body,
        from_email=from_email,
        recipient_list=recipient_list,
        html_message=transform(html_body),
        fail_silently=False,
    )
コード例 #18
0
ファイル: views.py プロジェクト: rahulkrishnan98/website
def contact(request):
    """
    View implement contact-us.
    """
    if request.method == 'POST':
        sender_name = str(request.POST['sender_name'])
        sender_email = str(request.POST['sender_email'])
        email_message = str(request.POST['mail_text'])
        email_from = "Amritapuri FOSS <*****@*****.**>"
        # if captcha field is not given
        if not (request.POST['recaptcha_challenge_field'] and request.POST['recaptcha_response_field']):
            return render_to_response('home.html',{'captcha_error':'Captcha required'}, RequestContext(request))
        recaptcha_challenge_field = request.POST['recaptcha_challenge_field']
        recaptcha_response_field = request.POST['recaptcha_response_field']
        recaptcha_remote_ip = ""
        captcha_is_correct = check_captcha(recaptcha_challenge_field, \
                            recaptcha_response_field,recaptcha_remote_ip)
        email_subject = "[Contact Us]:"+ sender_name 

        print captcha_is_correct
        #To-Do: Need to enable captcha once the site is hosted with 
        # with a domain name.
        #if captcha_is_correct:
        django_send_mail(email_subject, \
                            email_message, \
                            email_from, \
                            [sender_email, '*****@*****.**'], \
                            fail_silently= False)
        return render_to_response( 'contact_success.html', \
                {}, RequestContext(request))
        

    return HttpResponseRedirect('/')
コード例 #19
0
ファイル: task_mail.py プロジェクト: usnistgov/core_main_app
def send_mail(
    recipient_list,
    subject,
    body,
    fail_silently=True,
    sender=SERVER_EMAIL,
):
    """Send email.

    Args:
        recipient_list:
        subject:
        body:
        fail_silently:
        sender:

    Returns:

    """
    try:

        # Send mail
        django_send_mail(
            subject=EMAIL_SUBJECT_PREFIX + subject,
            message="",
            from_email=sender,
            recipient_list=recipient_list,
            html_message=body,
            fail_silently=fail_silently,
        )
    except Exception as e:
        raise e
コード例 #20
0
def send_mail(subject, html_body, text_body, to_address):
    logger.info('Sending notification email to {}: "{}"'.format(
        to_address, subject))
    django_send_mail(subject,
                     text_body,
                     settings.DEFAULT_FROM_EMAIL, [to_address],
                     html_message=html_body)
コード例 #21
0
ファイル: utils.py プロジェクト: pedrovzg/mootiro-maps
def send_mail(title='',
              message='',
              sender='MootiroMaps <*****@*****.**>',
              receivers=[],
              html=False):
    '''
    function for sending mails. If we are on debug (development) se will be
    sent by django mailer else will use the mailgun api.
    mailer.
    '''
    if settings.DEBUG and not html:
        django_send_mail(title,
                         message,
                         sender,
                         receivers,
                         fail_silently=False)
    else:
        data = {
            'from': 'MootiroMaps <*****@*****.**>',
            'to': receivers,
            'subject': title,
        }
        if html:
            data['html'] = message
        else:
            data['text'] = message

        requests.post(settings.MAILGUN_API_URL,
                      auth=('api', settings.MAILGUN_API_KEY),
                      data=data)
コード例 #22
0
ファイル: mail.py プロジェクト: shoark7/WPS_mysite_project
def send_test():
    django_send_mail(
        'ㅃㅃ',
        'Message',
        settings.EMAIL_HOST_USER,
        ['*****@*****.**'],
    )
コード例 #23
0
def send_test():
    django_send_mail(
        'subject',
        'message',
        settings.EMAIL_HOST_USER,
        ['*****@*****.**'],
        fail_silently=False,
    )
コード例 #24
0
ファイル: mail.py プロジェクト: Fastcampus-WPS/WPS-3rd
def send_mail(subject, message, recipient_list=None):
    default_recipient_list = ['*****@*****.**']
    django_send_mail(
        subject=subject,
        message=message,
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=recipient_list if recipient_list else default_recipient_list
    )
コード例 #25
0
def email_anything(recipients, subject, body):
    django_send_mail(subject=subject,
                     message='plain text not supported',
                     from_email=NO_REPLY,
                     recipient_list=recipients,
                     fail_silently=False,
                     html_message=body)
    return
コード例 #26
0
ファイル: mail.py プロジェクト: Fastcampus-WPS/WPS-3rd
def send_mail(subject, message, recipient_list=None):
    default_recipient_list = ['*****@*****.**']
    django_send_mail(
        subject=subject,
        message=message,
        from_email=settings.EMAIL_HOST_USER,
        # if recipient_list가 있을 경우에는 recipient_list, 없으면(None) default_recipient_list를 대입
        recipient_list=recipient_list if recipient_list else default_recipient_list
    )
コード例 #27
0
def send_mail(subject, message, recipient_list=None):
    default_recipient_list = ['*****@*****.**']
    django_send_mail(
        subject=subject,
        message=message,
        from_email=settings.EMAIL_HOST_USER,
        # if recipient_list가 있을 경우에는 recipient_list, 없으면(None) default_recipient_list를 대입
        recipient_list=recipient_list
        if recipient_list else default_recipient_list)
コード例 #28
0
def send_mail(subject, message, from_email, recipient_list, **kwargs):
    django_send_mail(subject, message, from_email, recipient_list, **kwargs)
    email = CmsEmail(
        from_email=from_email,
        to_emails=', '.join(recipient_list),
        subject=subject,
        body=message,
    )
    email.save()
コード例 #29
0
def send_mail(title, body, recipient_list, email_from=None, break_lines=True):
    if break_lines:
        body = '\n'.join(textwrap.fill(p) for p in body.split('\n'))
    if email_from is None:
        email_from = settings.EMAIL_FROM
    for email_to in ensure_list(recipient_list):
        try:
            django_send_mail(title, body, email_from, [email_to])
        except socket.error:
            pass
コード例 #30
0
def email_census_edit_notification(recipients, **values):
    (subject, html) = templates.get_subject_and_body(values)
    #subject = 'TESTING ONLY' + subject
    django_send_mail(subject=subject,
                     message='plain text not supported',
                     from_email=NO_REPLY,
                     recipient_list=recipients,
                     fail_silently=False,
                     html_message=html)
    return
コード例 #31
0
ファイル: utils.py プロジェクト: wuchengjiang/wagtail
def send_mail(email_subject, email_content, email_addresses, from_email=None):
    if not from_email:
        if hasattr(settings, 'WAGTAILADMIN_NOTIFICATION_FROM_EMAIL'):
            from_email = settings.WAGTAILADMIN_NOTIFICATION_FROM_EMAIL
        elif hasattr(settings, 'DEFAULT_FROM_EMAIL'):
            from_email = settings.DEFAULT_FROM_EMAIL
        else:
            from_email = 'webmaster@localhost'

    django_send_mail(email_subject, email_content, from_email, email_addresses)
コード例 #32
0
ファイル: util.py プロジェクト: kmshi/miroguide
def send_mail(title, body, recipient_list, email_from=None, break_lines=True):
    if break_lines:
        body = '\n'.join(textwrap.fill(p) for p in body.split('\n'))
    if email_from is None:
        email_from = settings.EMAIL_FROM
    for email_to in ensure_list(recipient_list):
        try:
            django_send_mail(title, body, email_from, [email_to])
        except socket.error:
            pass
コード例 #33
0
ファイル: utils.py プロジェクト: dangquocthai/wagtail
def send_mail(email_subject, email_content, email_addresses, from_email=None):
    if not from_email:
        if hasattr(settings, 'WAGTAILADMIN_NOTIFICATION_FROM_EMAIL'):
            from_email = settings.WAGTAILADMIN_NOTIFICATION_FROM_EMAIL
        elif hasattr(settings, 'DEFAULT_FROM_EMAIL'):
            from_email = settings.DEFAULT_FROM_EMAIL
        else:
            from_email = 'webmaster@localhost'

    django_send_mail(email_subject, email_content, from_email, email_addresses)
コード例 #34
0
ファイル: tasks.py プロジェクト: Rodion1198/django_example_b
def parse_quote():
    page = 1
    last_page = False
    already_saved_quotes = 1
    LINK = 'https://quotes.toscrape.com'

    while not last_page:
        url = f'{LINK}/page/{page}'
        r = requests.get(url)
        soup = BeautifulSoup(r.content, 'html.parser')
        quotes = soup.findAll('div', {'class': 'quote'})

        for item in quotes:
            if already_saved_quotes > 5:
                break
            else:
                title = item.select('.text')[0].contents[0]
                if Quot.objects.filter(title=title):
                    continue
                else:
                    author = item.select('.author')[0].contents[0]
                    if QuoteAuthor.objects.filter(author=author):
                        saved_author = QuoteAuthor.objects.get(author=author)
                    else:
                        link_author = LINK + item.find_all('a')[0].get('href')
                        r = requests.get(link_author)
                        soup = BeautifulSoup(r.content, 'html.parser')
                        date_of_birth = soup.find('span', {
                            'class': 'author-born-date'
                        }).contents[0]
                        born_in = soup.find('span', {
                            'class': 'author-born-location'
                        }).contents[0]
                        description = soup.find('div', {
                            'class': 'author-description'
                        }).contents[0]
                        saved_author: QuoteAuthor = QuoteAuthor(
                            author=author,
                            date_of_birth=date_of_birth,
                            born_in=born_in,
                            description=description)
                        saved_author.save()
                    quote_record: Quot = Quot(title=title, author=saved_author)
                    quote_record.save()
                    already_saved_quotes += 1
        if already_saved_quotes < 5:
            if soup.find('li', {'class': 'next'}) is None:
                last_page = True
            else:
                page += 1
        else:
            break
        if last_page is True:
            django_send_mail('Quotes is over!', 'All quotes added!',
                             '*****@*****.**', ['*****@*****.**'])
コード例 #35
0
def send_mail(recipient_list, subject, pathToTemplate, context={}, fail_silently=True, sender=SERVER_EMAIL):
    try:
        #Render the given template with context information
        template = loader.get_template(pathToTemplate)
        context = Context(context)
        message = template.render(context)
        # Send mail
        django_send_mail(subject=EMAIL_SUBJECT_PREFIX+subject, message='', from_email=sender, recipient_list=recipient_list,
                         html_message=message, fail_silently=fail_silently)
    except BadHeaderError, e:
        raise e
コード例 #36
0
ファイル: utils.py プロジェクト: aut-icpc/ACM-BackEnd
def send_mail(recipients, subject, content, user=None, password=None):

    message = content
    if password:
        message += "\n\n Your user is: %s \n Your password is %s" % (user,
                                                                     password)
    # email_from = settings.EMAIL_FROM
    email_from = "\"{}\" <{}>".format(settings.EMAIL_FROM,
                                      settings.EMAIL_HOST_USER)
    # recipient_list = [email, ]
    django_send_mail(subject, "", email_from, recipients, html_message=message)
コード例 #37
0
ファイル: tasks.py プロジェクト: zemogle/observation-portal
def send_mail(*args, **kwargs):
    # Add logging for emails - args[0] is subject and args[3] is recipients
    usernames = set()
    for email_address in args[3]:
        usernames = usernames.union(
            set(
                User.objects.filter(email=email_address).values_list(
                    'username', flat=True)))
    logger.info(
        f"Sending email to {','.join(usernames)} with subject {args[0]}")
    django_send_mail(*args, **kwargs)
コード例 #38
0
ファイル: mail.py プロジェクト: mailme/mailme
def send_mail_async(self, subject, message, from_email, recipient_list):
    try:
        django_send_mail(
            subject, message, from_email, recipient_list, fail_silently=False)
        self.logger.debug(
            'Successfully sent email message to %r.', ', '.join(recipient_list))
    except Exception as exc:
        # catching all exceptions b/c it could be any number of things
        # depending on the backend
        self.logger.warning(
            'Failed to send email message to %r, retrying.', ', '.join(recipient_list))
        self.retry(exc=exc, retry_countdown=60)
コード例 #39
0
ファイル: emails.py プロジェクト: mmilewski/entelib
def send(subject, msg, sender, recipients):
    '''
    Sends emails. Parameters are defined like in django's send_mail.
    '''
    config = Config()
    if config.get_bool('log_send_emails'):
        log_email(sender, recipients, subject, msg)
    if config.get_bool('send_emails'):
        try:
            django_send_mail(subject, msg, sender, recipients)
        except SMTPRecipientsRefused:
            return 'Incorrect e-mail address - e-mail not sent'
    return None
コード例 #40
0
def send_mail(request, feedback, fail_silently=True):
    message = _("Your site %(host)s received feedback from %(user)s.\n"
                "The comments were:\n"
                "%(note)s.\n\n"
                "See the full feedback content here: %(url)s")\
              % {'host': request.get_host(), 'user': str(request.user), 'note': feedback.comment,
                 'url': request.build_absolute_uri(
                     reverse('admin:tellme_feedback_change', args=(feedback.id,)))}
    django_send_mail(_('[%(host)s] Received feedback') %
                     {'host': request.get_host()},
                     message,
                     settings.SERVER_EMAIL, [settings.TELLME_FEEDBACK_EMAIL],
                     fail_silently=fail_silently)
コード例 #41
0
ファイル: api.py プロジェクト: bmbouter/CeleryManagement
def send_email(subject, message, from_email, recipient_list, auth_user=None, 
               auth_password=None):
    """ Send an email using Django's email interface. 
        
        recipient_list:
            A list of emails--each email is a string.
            
        auth_user, auth_password:
            Username and password for the SMTP server.  If they are not 
            provided, Django will use the EMAIL_HOST_USER and 
            EMAIL_HOST_PASSWORD settings, respectively.
    """
    django_send_mail(subject, message, from_email, recipient_list, 
                     auth_user=auth_user, auth_password=auth_password)
コード例 #42
0
ファイル: mail.py プロジェクト: WillianPaiva/sparks
def send_mail(*args, **kwargs):
    """ Wraps the Django :func:`send_mail` function into a parallel thread
        for immediate reactivity on the web-front side.

        .. versionadded:: 1.17
    """

    parallel = kwargs.pop("parallel", False)

    if parallel:
        BatcherThread(django_send_mail, args=args, kwargs=kwargs, parallel=True).start()

    else:
        django_send_mail(*args, **kwargs)
コード例 #43
0
def send_email(job):
    logger.info("Sending email with subject %s to %s", job.workspace['subject'], ", ".join(job.workspace['recipient_list']))

    job.workspace['mail_params']['site_url'] = settings.SITE_URL

    msg_plain = render_to_string(job.workspace['plain_template'], job.workspace['mail_params'])
    msg_html = render_to_string(job.workspace['html_template'], job.workspace['mail_params'])

    django_send_mail(
        subject=job.workspace['subject'],
        message=msg_plain,
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=job.workspace['recipient_list'],
        html_message=msg_html,
    )
コード例 #44
0
ファイル: utils.py プロジェクト: mccammos/zamboni
def send_mail(subject, message, from_email=None, recipient_list=None,
              fail_silently=False):
    """
    A wrapper around django.core.mail.send_mail.

    Adds blacklist checking and error logging.
    """
    log = logging.getLogger('z.amo')

    if not recipient_list:
        return True

    if not from_email:
        from_email = settings.EMAIL_FROM_DEFAULT

    # Prune blacklisted emails.
    white_list = []
    for email in recipient_list:
        if email.lower() in settings.EMAIL_BLACKLIST:
            log.debug('Blacklisted email removed from list: %s' % email)
        else:
            white_list.append(email)
    try:
        if white_list:
            result = django_send_mail(subject, message, from_email, white_list,
                                      fail_silently=False)
        else:
            result = True
    except Exception as e:
        result = False
        log.error('send_mail failed with error: %s' % e)
        if not fail_silently:
            raise

    return result
コード例 #45
0
def send_mail(subject, message, from_email, recipients):
    """send mail to recipients
    
    this method use django-mailer_ ``send_mail`` method when
    the app is in ``INSTALLED_APPS``

    .. Note::
        django-mailer_ ``send_mail`` is not used duaring unittest
        because it is a little bit difficult to check the number of
        mail sent in unittest for both django-mailer and original
        django ``send_mail``

    .. _django-mailer: http://code.google.com/p/django-mailer/
    """
    from django.conf import settings
    from django.core.mail import send_mail as django_send_mail
    import sys

    if "test" not in sys.argv and "mailer" in settings.INSTALLED_APPS:
        try:
            from mailer import send_mail

            return send_mail(subject, message, from_email, recipients)
        except ImportError:
            pass
    return django_send_mail(subject, message, from_email, recipients)
コード例 #46
0
ファイル: forms.py プロジェクト: gordio/gordio-site-django
 def send_mail(self):
     return django_send_mail(
         _("{0} New message from site".format(settings.EMAIL_PREFIX)),
         self.cleaned_data['content'],
         self.cleaned_data['email'],
         [manager[1] for manager in settings.MANAGERS]
     )
コード例 #47
0
ファイル: mail.py プロジェクト: frecar/focus
def _send_mail(subject, message, fromMail, toMails, fail_silently=False):
    recipients = []
    recipients.extend(toMails)

    #Always send debug email
    debug_subject = "[debug] subject: %s" % subject
    debug_message = "from: %s, to: %s\n\n%s" % (fromMail, recipients, message)
    mail = django_send_mail(debug_subject, debug_message, fromMail, [settings.DEBUG_EMAIL], fail_silently=fail_silently)

    #Clean recipient list for non-emails
    for email in recipients:
        if email == "":
            recipients.remove(email)

    #Send actual email if not in debug mode
    if not settings.DEBUG and len(recipients) > 0:
        mail = django_send_mail(subject, message, fromMail, recipients, fail_silently=fail_silently)
コード例 #48
0
ファイル: utils.py プロジェクト: anderspetersson/rida
def send_email(subject, template_name, email, context=None):
    """
    Sends email using a template.
    """

    txt_template_name = 'email/%s.txt' % template_name
    html_template_name = 'email/%s.html' % template_name

    txt_message = loader.render_to_string(txt_template_name, context)
    html_message = loader.render_to_string(html_template_name, context)

    django_send_mail(
        subject=subject,
        message=txt_message,
        from_email=settings.DEFAULT_FROM_EMAIL,
        recipient_list=[email],
        html_message=html_message
    )
コード例 #49
0
def sendmail_after_userreg(email,password):
    email_subject = 'AYUDH \'14 User Registration'
    email_from = 'AYUDH 2014'
    email_message = """
    You have been successfully registered as a USER for AYUDH Amritapuri.
    
    Email   : """ + email + """
    Password: """ + password + """
    
    We look forward to your participation in AYUDH '14. Feel free to ask us any queries
    regarding the same.

    --
    AYUDH Team
    """    

    django_send_mail(email_subject, email_message,email_from,[email], fail_silently=False)
    """
コード例 #50
0
ファイル: utils.py プロジェクト: Chris-May/wagtail
def send_mail(subject, message, recipient_list, from_email=None, **kwargs):
    if not from_email:
        if hasattr(settings, 'WAGTAILADMIN_NOTIFICATION_FROM_EMAIL'):
            from_email = settings.WAGTAILADMIN_NOTIFICATION_FROM_EMAIL
        elif hasattr(settings, 'DEFAULT_FROM_EMAIL'):
            from_email = settings.DEFAULT_FROM_EMAIL
        else:
            from_email = 'webmaster@localhost'

    return django_send_mail(subject, message, from_email, recipient_list, **kwargs)
コード例 #51
0
ファイル: models.py プロジェクト: studioaceofspade/Torch
def send_email(username):
    user = User.objects.get(
        username=username,
    )
    new_password = str(uuid.uuid4())
    user.set_password(new_password)
    user.save()
    django_send_mail(
        subject='Forgot password',
        message=dedent('''
            Your password has been reset to:

            %s

            Please log in and change the password to something easier to read.
        ''' % new_password),
        from_email='*****@*****.**',
        recipient_list=[username],
        fail_silently=True,
    )
コード例 #52
0
ファイル: utils.py プロジェクト: sebbacon/trevor
def send_mail(user=None,
              subject=None,
              message=None,
              mail_from=settings.DEFAULT_FROM_EMAIL):
    """Send an email with the standard unsubscribe footer
    """
    site = Site.objects.get_current()
    return django_send_mail(subject,
                            message,
                            mail_from,
                            [user.email,])
コード例 #53
0
ファイル: utils.py プロジェクト: ACLARKNET/aclarknet-database
def send_mail(request, subject, message, to):
    recipients = []
    sender = settings.DEFAULT_FROM_EMAIL
    subject = subject
    message = message
    recipients.append(to)

    # http://stackoverflow.com/a/28476681/185820
    html_message = render_to_string('cerberus-responsive.html',
                                    {'username': to})
    try:
        django_send_mail(
            subject,
            message,
            sender,
            recipients,
            fail_silently=False,
            html_message=html_message)
    except SMTPSenderRefused:
        messages.add_message(request, messages.INFO, 'SMTPSenderRefused!')
コード例 #54
0
ファイル: utils.py プロジェクト: it3s/mootiro-maps
def send_mail(title="", message="", sender=None, receivers=[], html=False):
    """Function for sending mails.

    If we are on debug (development) the email message will be sent by django
    mailer, otherwise we will use the mailgun api.

    """
    if not sender:
        sender = getattr(settings, "EMAIL_SENDER", "MootiroMaps <*****@*****.**>")

    if settings.DEBUG and not html:
        django_send_mail(title, message, sender, receivers, fail_silently=False)
    else:
        data = {"from": sender, "to": receivers, "subject": title}
        if html:
            data["html"] = message
        else:
            data["text"] = message

        requests.post(settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_API_KEY), data=data)
コード例 #55
0
def send_mail(product, subscription, price):
    """
    Sends an email using the appropriate settings for formatting aso.
    :param product: the product
    :type product: price_monitor.models.Product
    :param subscription: the subscription
    :type subscription: price_monitor.models.Subscription
    :param price: the current price
    :type price: price_monitor.models.Price
    """
    django_send_mail(
        _(app_settings.PRICE_MONITOR_I18N_EMAIL_NOTIFICATION_SUBJECT) % {'product': product.title},
        _(app_settings.PRICE_MONITOR_I18N_EMAIL_NOTIFICATION_BODY) % {
            'price_limit': subscription.price_limit,
            'currency': price.currency,
            'price': price.value,
            'product_title': product.title,
            'link': product.offer_url,
        },
        app_settings.PRICE_MONITOR_EMAIL_SENDER,
        [subscription.email_notification.email],
        fail_silently=False,
    )
コード例 #56
0
ファイル: helper.py プロジェクト: Anagha22/arts_fest
def sendmail_after_pass_change(username, password, email_to):
    """
    Email notification to be send after user password change
    """
    email_subject = 'FOSS@Amrita User Password change'
    email_from = 'Amritapuri FOSS <*****@*****.**>'
    email_message = """
    Your password has been recently changed.
    
    Username: """ + username + """
    New Password: """ + password + """
    
    --
    Amritapuri FOSS
    http://amritapurifoss.in
    [email protected]
    """    

    django_send_mail(email_subject, \
            email_message, \
            email_from, \
            [email_to], \
            fail_silently = False)
コード例 #57
0
ファイル: helper.py プロジェクト: Anagha22/arts_fest
def sendmail_after_userreg(username, password, email_to):
    """
    Email notification to be send to the user
    """
    email_subject = 'FOSS@Amrita User Registration'
    email_from = 'Amritapuri FOSS <*****@*****.**>'
    email_message = """
    You have been successfully registered as a USER at Amritapuri FOSS.
    
    Username: """ + username + """
    Password: """ + password + """
    
    --
    Amritapuri FOSS
    http://amritapurifoss.in
    [email protected]
    """    

    django_send_mail(email_subject, \
            email_message, \
            email_from, \
            [email_to], \
            fail_silently = False)
コード例 #58
0
ファイル: helper.py プロジェクト: Anagha22/arts_fest
def notify_new_user(username, email):
    """
    Notifies the admins regarding a successful user registration
    """
    email_subject = "[FOSS@Amrita][User Registered] " + username
    email_from = "Amritapuri FOSS <*****@*****.**>"
    email_message = """
    A new user has been registered today!
    Username: """ + username + """
    Email: """ + email + """

    --
    Email deamon
    Amritapuri FOSS
    http://amritapurifoss.in
    [email protected]
    """

    django_send_mail(email_subject, \
            email_message, \
            email_from, \
            ADMINS_EMAIL, \
            fail_silently = False)