我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用django.conf.settings.SERVER_EMAIL。
def not_found_scenes_alert(): """Send email if there are Scene Requests that were not found in AWS and Google Earth servers and need manual download. """ yesterday = date.today() - timedelta(days=1) if SceneRequest.objects.filter(status='not_found', creation_date__gte=yesterday).count() > 0: try: send_multipart_email( subject='Not Found Scene Requests', html_template='imagery/email_not_found_scenerequests.html', from_email=settings.SERVER_EMAIL, to_email=settings.NOT_FOUND_SCENES_ADMIN_EMAILS ) except AttributeError: logger.error( """There are scene requests that require manual download but we could not send email because the variables SERVER_EMAIL or NOT_FOUND_SCENES_ADMIN_EMAILS are not configured in your settings.""")
def send_error_report(url, exception, trace): """Send email when an error occurs.""" if settings.DEBUG is False: email_context = { 'site': url, 'exception': exception, 'traceback': trace } message = get_template('scheduler_core/error_report_parsing.html').render(email_context) error_email = EmailMessage('[MovieScheduler] Parsing Error Report', message, settings.SERVER_EMAIL, settings.ADMINS) error_email.content_subtype = 'html' error_email.send(fail_silently=False) else: print("Exception: " + str(exception)) print("Traceback: ") print(trace)
def create_profile(sender, **kwargs): user = kwargs["instance"] if kwargs["created"]: default_plan = Plan.objects.get(pk=Plan.DEFAULT_PK) up = Profile(user=user, plan=default_plan) up.save() try: for tg in TalkGroupAccess.objects.filter(default_group=True): up.talkgroup_access.add(tg) except OperationalError: pass try: new_user_email = SiteOption.objects.get(name='SEND_ADMIN_EMAIL_ON_NEW_USER') if new_user_email.value_boolean_or_string() == True: send_mail( 'New {} User {}'.format(settings.SITE_TITLE, user.username), 'New User {} {} Username {} Email {} just registered'.format(user.first_name, user.last_name, user.username, user.email), settings.SERVER_EMAIL, [ mail for name, mail in settings.ADMINS], fail_silently=False, ) except (SiteOption.DoesNotExist, OperationalError): pass
def send_email(self, rendered_notification, notification): from django.utils.safestring import SafeText assert (isinstance(rendered_notification, SafeText)) try: # TODO: send_mass_mail to send to multiple recipients # mail_managers(u'{}'.format(notification.title), # u'{}'.format(''), # fail_silently=False, html_message=rendered_notification) send_mail('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, notification.title), u'{}'.format(''), from_email=settings.SERVER_EMAIL, recipient_list=[self.email_to, ], fail_silently=False, html_message=rendered_notification) except Exception as e: raise e
def trustee_send_url(request, election, trustee_uuid): trustee = Trustee.get_by_election_and_uuid(election, trustee_uuid) url = trustee.admin_url() body = """ You are a trustee for %s. Your trustee dashboard is at %s -- Helios """ % (election.name, url) helios_utils.send_email(settings.SERVER_EMAIL, ["%s <%s>" % (trustee.name, trustee.email)], 'your trustee homepage for %s' % election.name, body) logging.info("URL %s " % url) return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(list_trustees_view, args = [election.uuid]))
def mixnet_send_url(request, election, mixnet_index): mixnet = election.mixnets.filter()[int(mixnet_index)] url = mixnet.admin_url() body = """ You are a mixnet for %s. Your mixnet dashboard is at %s -- Helios """ % (election.name, url) helios_utils.send_email(settings.SERVER_EMAIL, ["%s <%s>" % (mixnet.name, mixnet.email)], 'your mixnet homepage for %s' % election.name, body) logging.info("URL %s " % url) return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(list_mixnets_view, args = [election.uuid]))
def mail_admins(subject, message, fail_silently=False, priority="medium"): from django.utils.encoding import force_unicode from django.conf import settings from mailer.models import Message priority = PRIORITY_MAPPING[priority] subject = settings.EMAIL_SUBJECT_PREFIX + force_unicode(subject) message = force_unicode(message) if len(subject) > 100: subject = u"%s..." % subject[:97] for name, to_address in settings.ADMINS: Message(to_address=to_address, from_address=settings.SERVER_EMAIL, subject=subject, message_body=message, priority=priority).save()
def mail_managers(subject, message, fail_silently=False, priority="medium"): from django.utils.encoding import force_unicode from django.conf import settings from mailer.models import Message priority = PRIORITY_MAPPING[priority] subject = settings.EMAIL_SUBJECT_PREFIX + force_unicode(subject) message = force_unicode(message) if len(subject) > 100: subject = u"%s..." % subject[:97] for name, to_address in settings.MANAGERS: Message(to_address=to_address, from_address=settings.SERVER_EMAIL, subject=subject, message_body=message, priority=priority).save()
def status_mail(request): form = TestEmailForm(request.POST or None) if form.is_valid(): body = """This email was sent as a request to test the Sentry outbound email configuration.""" try: send_mail( '%s Test Email' % (settings.EMAIL_SUBJECT_PREFIX,), body, settings.SERVER_EMAIL, [request.user.email], fail_silently=False ) except Exception as e: form.errors['__all__'] = [six.text_type(e)] return render_to_response('sentry/admin/status/mail.html', { 'form': form, 'EMAIL_HOST': settings.EMAIL_HOST, 'EMAIL_HOST_PASSWORD': bool(settings.EMAIL_HOST_PASSWORD), 'EMAIL_HOST_USER': settings.EMAIL_HOST_USER, 'EMAIL_PORT': settings.EMAIL_PORT, 'EMAIL_USE_TLS': settings.EMAIL_USE_TLS, 'SERVER_EMAIL': settings.SERVER_EMAIL, }, request)
def __init__(self, subject, context=None, template=None, html_template=None, body=None, html_body=None, headers=None, reference=None, reply_reference=None, from_email=None): assert not (body and template) assert not (html_body and html_template) assert context or not (template or html_template) self.subject = subject self.context = context or {} self.template = template self.html_template = html_template self._txt_body = body self._html_body = html_body self.headers = headers self.reference = reference # The object that generated this message self.reply_reference = reply_reference # The object this message is replying about self.from_email = from_email or settings.SERVER_EMAIL self._send_to = set()
def __init__(self, subject, message, fail_silently=False, html_message=None, connection=None): self.connection = connection self.subject = subject self.message = message self.recipient_list = [a[1] for a in settings.ADMINS] self.from_email = settings.SERVER_EMAIL self.fail_silently = fail_silently self.html_message = html_message threading.Thread.__init__(self)
def run(self): if not settings.ADMINS: return mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, self.subject), self.message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], connection=self.connection) if self.html_message: mail.attach_alternative(self.html_message, 'text/html') try: mail.send(fail_silently=self.fail_silently) except Exception as e: logger.exception(e)
def mail_admins(subject, message, fail_silently=False, connection=None, html_message=None): """Sends a message to the admins, as defined by the ADMINS setting.""" if not settings.ADMINS: return mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], connection=connection) if html_message: mail.attach_alternative(html_message, 'text/html') mail.send(fail_silently=fail_silently)
def mail_managers(subject, message, fail_silently=False, connection=None, html_message=None): """Sends a message to the managers, as defined by the MANAGERS setting.""" if not settings.MANAGERS: return mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], connection=connection) if html_message: mail.attach_alternative(html_message, 'text/html') mail.send(fail_silently=fail_silently)
def mail_admins(subject, message, fail_silently=False, connection=None, html_message=None): """Sends a message to the admins, as defined by the ADMINS setting.""" if not settings.ADMINS: return mail = EmailMultiAlternatives( '%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.ADMINS], connection=connection, ) if html_message: mail.attach_alternative(html_message, 'text/html') mail.send(fail_silently=fail_silently)
def mail_managers(subject, message, fail_silently=False, connection=None, html_message=None): """Sends a message to the managers, as defined by the MANAGERS setting.""" if not settings.MANAGERS: return mail = EmailMultiAlternatives( '%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, [a[1] for a in settings.MANAGERS], connection=connection, ) if html_message: mail.attach_alternative(html_message, 'text/html') mail.send(fail_silently=fail_silently)
def post_feedback(request): if request.method == 'POST' and request.is_ajax(): # Copy Post data names into names used into the model in order to automatically create the model/form # from the request dicts feedback = json.loads(request.POST["feedback"]) if request.user.id: data = {'url': feedback['url'], 'browser': json.dumps(feedback['browser']), 'comment': feedback['note'], 'user': request.user.id} else: data = {'url': feedback['url'], 'browser': json.dumps(feedback['browser']), 'comment': feedback['note'], 'email': feedback['email']} imgstr = feedback['img'].split(';base64,')[1] file = {'screenshot': ContentFile(b64decode(imgstr), name="screenshot_" + get_random_string(6) + ".png")} form = FeedbackForm(data, file) # check whether it's valid: if form.is_valid(): f = form.save() if hasattr(settings, 'TELLME_FEEDBACK_EMAIL'): 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['note'], 'url': request.build_absolute_uri( urlresolvers.reverse('admin:tellme_feedback_change', args=(f.id,)))} send_mail( _('[%(host)s] Received feedback') % {'host': request.get_host()}, message, settings.SERVER_EMAIL, [settings.TELLME_FEEDBACK_EMAIL], fail_silently=True) return JsonResponse({}) else: return JsonResponse({'error': dict(form.errors)}) else: return HttpResponseBadRequest()
def send_admin_email(subject, text): send_mail(subject, text, settings.SERVER_EMAIL, settings.ADMIN_EMAILS, fail_silently=True)