def send_mail(request, target): if target is None: target = 'pionniers' if target != 'pionniers' and not request.user.is_staff: raise Http404 emails = list(settings.EMAIL_COPY_RECIPIENT) if target == 'pionniers' or target == 'all': emails += [user.email for user in User.objects.all()] if target == 'parents' or target == 'all': emails += [user.parents_email for user in User.objects.all()] emails = ', '.join(filter(lambda x: x is not None, emails)) success = error = None if request.method == 'POST': try: dj_send_mail( request.POST.get('subject', ''), request.POST.get('body'), settings.DEFAULT_FROM_EMAIL, [emails] ) success = True except Exception as e: error = str(e) return render(request, 'users/send-email.html', { 'nb_targets': emails.count('@'), 'body': request.POST.get('body', ''), 'subject': request.POST.get('subject', ''), 'error': error, 'success': success, })
def send_mail(receiver, subject, payload): print('sending mail to', receiver) dj_send_mail(subject=subject, from_email=EMAIL_HOST_USER, recipient_list=receiver, message=payload, html_message=payload)
def _send_mail(msg_to, msg_subjects, msg_body, msg_from=settings.DEFAULT_FROM_EMAIL): if isinstance(msg_to, str) or isinstance(msg_to, unicode): msg_to = [msg_to] dj_send_mail(msg_subjects, msg_body, msg_from, msg_to)
def send_mail(title, message, receivers): print('-----开始发送邮件----') dj_send_mail(title, '', html_message=message, from_email='*****@*****.**', recipient_list=receivers) print('--发送完成!-')
def send_mail(title, message, receivers): print('----开始发送右键----') dj_send_mail(title, '', html_message=message, from_email='*****@*****.**', recipient_list=receivers) print('发送完成!')
def _smtp_send(mail): """ Uses SMTP settings to send an email. Do not call this function directly. """ from apps.mail.models import Mail to_email = getattr(mail.user, mail.user.get_email_field_name()) try: sent = dj_send_mail( mail.subject, mail.body, settings.DEFAULT_FROM_EMAIL, [to_email], html_message=mail.body, fail_silently=False, ) mail.status = Mail.SENT mail.save() except SMTPException as e: mail.status = Mail.ERROR mail.save() raise e return sent
def send_mail(request, subject, to, template=None, context=None, content=None): """Useful wrapper around django's send_mail.""" if isinstance(to, basestring): to = [to] # send_mail expects a list of recipients if not content: if 'link' in context: context['link'] = request.build_absolute_uri(context['link']) content = render_to_string(template, context) content = content.strip() from_ = settings.DEFAULT_FROM_EMAIL try: dj_send_mail(subject, content, from_, to) return True except SocketError as e: logger.error("Failed to send e-mail: {}".format(e)) return False