Python django.conf.settings.SERVER_EMAIL Examples
The following are 18
code examples of django.conf.settings.SERVER_EMAIL().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.conf.settings
, or try the search function
.
Example #1
Source File: shortcuts.py From yats with MIT License | 6 votes |
def mail_file(request, file_id): from yats.models import tickets_files io = tickets_files.objects.get(pk=file_id) ticket_id = io.ticket_id int_rcpt, pub_rcpt = get_mail_recipient_list(request, ticket_id) tic = get_ticket_model().objects.get(pk=ticket_id) if len(int_rcpt) > 0: body = '%s\n%s: %s\n%s: %s\n%s: %s\n\n%s' % (_('new file added'), _('file name'), io.name, _('file size'), io.size, _('content type'), io.content_type, get_ticket_url(request, ticket_id)) try: send_mail('%s#%s: %s - %s' % (settings.EMAIL_SUBJECT_PREFIX, tic.id, _('new file'), tic.caption), body, settings.SERVER_EMAIL, int_rcpt, False) except Exception: messages.add_message(request, messages.ERROR, _('mail not send: %s') % sys.exc_info()[1]) if len(pub_rcpt) > 0: body = '%s\n%s: %s\n%s: %s\n%s: %s\n\n%s' % (_('new file added'), _('file name'), io.name, _('file size'), io.size, _('content type'), io.content_type, get_ticket_url(request, ticket_id, for_customer=True)) try: send_mail('%s#%s: %s - %s' % (settings.EMAIL_SUBJECT_PREFIX, tic.id, _('new file'), tic.caption), body, settings.SERVER_EMAIL, int_rcpt, False) except Exception: messages.add_message(request, messages.ERROR, _('mail not send: %s') % sys.exc_info()[1])
Example #2
Source File: views.py From peering-manager with Apache License 2.0 | 6 votes |
def post(self, request, *args, **kwargs): autonomous_system = get_object_or_404(AutonomousSystem, asn=kwargs["asn"]) if not autonomous_system.can_receive_email: redirect(autonomous_system.get_absolute_url()) form = AutonomousSystemEmailForm(request.POST) form.fields[ "recipient" ].choices = autonomous_system.get_contact_email_addresses() if form.is_valid(): sent = send_mail( form.cleaned_data["subject"], form.cleaned_data["body"], settings.SERVER_EMAIL, [form.cleaned_data["recipient"]], ) if sent == 1: messages.success(request, "Email sent.") else: messages.error(request, "Unable to send the email.") return redirect(autonomous_system.get_absolute_url())
Example #3
Source File: shortcuts.py From yats with MIT License | 6 votes |
def mail_comment(request, comment_id): from yats.models import tickets_comments com = tickets_comments.objects.get(pk=comment_id) ticket_id = com.ticket_id int_rcpt, pub_rcpt = get_mail_recipient_list(request, ticket_id) tic = get_ticket_model().objects.get(pk=ticket_id) if len(int_rcpt) > 0: try: send_mail('%s#%s: %s - %s' % (settings.EMAIL_SUBJECT_PREFIX, tic.id, _('new comment'), tic.caption), '%s\n\n%s' % (com.comment, get_ticket_url(request, ticket_id)), settings.SERVER_EMAIL, int_rcpt, False) except Exception: messages.add_message(request, messages.ERROR, _('mail not send: %s') % sys.exc_info()[1]) if len(pub_rcpt) > 0: try: send_mail('%s#%s: %s - %s' % (settings.EMAIL_SUBJECT_PREFIX, tic.id, _('new comment'), tic.caption), '%s\n\n%s' % (com.comment, get_ticket_url(request, ticket_id, for_customer=True)), settings.SERVER_EMAIL, pub_rcpt, False) except Exception: messages.add_message(request, messages.ERROR, _('mail not send: %s') % sys.exc_info()[1])
Example #4
Source File: views.py From dirigible-spreadsheet with MIT License | 6 votes |
def submit(request): send_mail( "User feedback from Dirigible", dedent(""" Username: %s Email address: %s Page: %s Message: %s """) % ( request.POST["username"], request.POST["email_address"], request.META['HTTP_REFERER'], request.POST["message"] ), settings.SERVER_EMAIL, [settings.FEEDBACK_EMAIL] ) return HttpResponse("OK")
Example #5
Source File: models.py From trunk-player with MIT License | 6 votes |
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
Example #6
Source File: views.py From trunk-player with MIT License | 5 votes |
def form_valid(self, form): try: update_unit_email = SiteOption.objects.get(name='SEND_ADMIN_EMAIL_ON_UNIT_NAME') if update_unit_email.value_boolean_or_string() == True: Unit = form.save() send_mail( 'Unit ID Change', 'User {} updated unit ID {} Now {}'.format(self.request.user, Unit.dec_id, Unit.description), settings.SERVER_EMAIL, [ mail for name, mail in settings.ADMINS], fail_silently=False, ) except SiteOption.DoesNotExist: pass return super().form_valid(form)
Example #7
Source File: shortcuts.py From yats with MIT License | 5 votes |
def mail_ticket(request, ticket_id, form, **kwargs): int_rcpt, pub_rcpt = list(get_mail_recipient_list(request, ticket_id)) tic = get_ticket_model().objects.get(pk=ticket_id) if not tic.assigned: if 'rcpt' in kwargs and kwargs['rcpt']: rcpts = kwargs['rcpt'].split(',') for rcpt in rcpts: if rcpt not in int_rcpt: int_rcpt.append(rcpt) new, old = field_changes(form) if len(int_rcpt) > 0: try: new['author'] = tic.c_user send_mail('%s#%s - %s' % (settings.EMAIL_SUBJECT_PREFIX, tic.id, tic.caption), '%s\n\n%s' % (format_chanes(new, True), get_ticket_url(request, ticket_id)), settings.SERVER_EMAIL, int_rcpt, False) except: if not kwargs.get('is_api', False): messages.add_message(request, messages.ERROR, _('mail not send: %s') % sys.exc_info()[1]) if len(pub_rcpt) > 0 and has_public_fields(new): try: new['author'] = tic.u_user send_mail('%s#%s - %s' % (settings.EMAIL_SUBJECT_PREFIX, tic.id, tic.caption), '%s\n\n%s' % (format_chanes(new, False), get_ticket_url(request, ticket_id, for_customer=True)), settings.SERVER_EMAIL, pub_rcpt, False) except: if not kwargs.get('is_api', False): messages.add_message(request, messages.ERROR, _('mail not send: %s') % sys.exc_info()[1])
Example #8
Source File: db_dump.py From pm-trading-db with MIT License | 5 votes |
def send_email(self, filename): # send email email = EmailMultiAlternatives( subject='[Olympia tradingdb backup]', body='tradingdb backup attached.', from_email=settings.SERVER_EMAIL, to=[a[1] for a in settings.ADMINS] ) email.attach_file(filename) email.send()
Example #9
Source File: server.py From Inboxen with GNU Affero General Public License v3.0 | 5 votes |
def forward_to_admins(message, local=None, domain=None): if message.is_bounce(): # log and swallow the message log.warning("Detected message bounce %s, subject: %s", message, message["Subject"]) return try: Relay().deliver(message, To=[m[1] for m in settings.ADMINS], From=settings.SERVER_EMAIL) except Exception as excp: log.exception("Error while forwarding admin message %s: %s", id(message), excp) raise SMTPError(450, "Error while forwarding admin message %s" % id(message))
Example #10
Source File: __init__.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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)
Example #11
Source File: __init__.py From luscan-devel with GNU General Public License v2.0 | 5 votes |
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)
Example #12
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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)
Example #13
Source File: test_views.py From dirigible-spreadsheet with MIT License | 5 votes |
def test_submit_with_message_and_email_address_and_username_sends_admin_email_with_all_three(self, mock_send_mail): request = HttpRequest() request.POST["message"] = "a test message" request.POST["email_address"] = "a test email address" request.POST["username"] = "a test username" request.META['HTTP_REFERER'] = 'a test page' response = submit(request) self.assertTrue(isinstance(response, HttpResponse)) self.assertEquals(response.content, "OK") self.assertCalledOnce( mock_send_mail, "User feedback from Dirigible", dedent(""" Username: a test username Email address: a test email address Page: a test page Message: a test message """), settings.SERVER_EMAIL, [settings.FEEDBACK_EMAIL] )
Example #14
Source File: test_openedx_appserver.py From opencraft with GNU Affero General Public License v3.0 | 5 votes |
def test_provision_failed_exception_email(self, mock_consul): """ Tests that provision_failed sends email when called from exception handler """ appserver = make_test_appserver() reason = "something went wrong" log_lines = ["log line1", "log_line2"] exception_message = "Something Bad happened Unexpectedly" exception = Exception(exception_message) try: raise exception except Exception: # pylint: disable=broad-except appserver.provision_failed_email(reason, log_lines) expected_subject = OpenEdXAppServer.EmailSubject.PROVISION_FAILED.format( name=appserver.name, instance_name=appserver.instance.name, ) expected_recipients = [admin_tuple[1] for admin_tuple in settings.ADMINS] self.assertEqual(len(django_mail.outbox), 1) mail = django_mail.outbox[0] self.assertIn(expected_subject, mail.subject) self.assertIn(appserver.name, mail.body) self.assertIn(appserver.instance.name, mail.body) self.assertIn(reason, mail.body) self.assertEqual(mail.from_email, settings.SERVER_EMAIL) self.assertEqual(mail.to, expected_recipients) self.assertEqual(len(mail.attachments), 2) self.assertEqual(mail.attachments[0], ("provision.log", "\n".join(log_lines), "text/plain")) name, content, mime_type = mail.attachments[1] self.assertEqual(name, "debug.html") self.assertIn(exception_message, content) self.assertEqual(mime_type, "text/html")
Example #15
Source File: test_openedx_appserver.py From opencraft with GNU Affero General Public License v3.0 | 5 votes |
def test_provision_failed_email(self, mock_consul): """ Tests that provision_failed sends email when called from normal program flow """ additional_monitoring_emails = ['additionalmonitoring@localhost'] failure_emails = ['provisionfailed@localhost'] appserver = make_test_appserver() appserver.instance.additional_monitoring_emails = additional_monitoring_emails appserver.instance.provisioning_failure_notification_emails = failure_emails reason = "something went wrong" log_lines = ["log line1", "log_line2"] appserver.provision_failed_email(reason, log_lines) expected_subject = OpenEdXAppServer.EmailSubject.PROVISION_FAILED.format( name=appserver.name, instance_name=appserver.instance.name, ) # failure_emails isn't included here because they get a different type of email (an urgent one) expected_recipients = [admin_tuple[1] for admin_tuple in settings.ADMINS] self.assertEqual(len(django_mail.outbox), 1) mail = django_mail.outbox[0] self.assertIn(expected_subject, mail.subject) self.assertIn(appserver.name, mail.body) self.assertIn(appserver.instance.name, mail.body) self.assertIn(reason, mail.body) self.assertEqual(mail.from_email, settings.SERVER_EMAIL) self.assertEqual(mail.to, expected_recipients) self.assertEqual(len(mail.attachments), 1) self.assertEqual(mail.attachments[0], ("provision.log", "\n".join(log_lines), "text/plain"))
Example #16
Source File: utilities.py From opencraft with GNU Affero General Public License v3.0 | 5 votes |
def _mail_admins_with_attachment( subject, message, fail_silently=True, connection=None, html_message=None, attachments=None, extra_recipients: Optional[List[str]] = None, ): """ Mimics mail_admins, but allows attaching files to the message """ if not settings.ADMINS and not extra_recipients: return recipients = [a[1] for a in settings.ADMINS] + extra_recipients mail = EmailMultiAlternatives( "%s%s" % (settings.EMAIL_SUBJECT_PREFIX, subject), message, settings.SERVER_EMAIL, recipients, connection=connection ) if html_message: mail.attach_alternative(html_message, "text/html") if attachments: for attachment_name, attachment_content, attachment_mime in attachments: mail.attach(attachment_name, attachment_content, attachment_mime) mail.send(fail_silently=fail_silently) # Functions #####################################################################
Example #17
Source File: __init__.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
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)
Example #18
Source File: tasks.py From django-import-export-celery with GNU Lesser General Public License v3.0 | 4 votes |
def run_export_job(pk): log.info("Exporting %s" % pk) export_job = models.ExportJob.objects.get(pk=pk) resource_class = export_job.get_resource_class() queryset = export_job.get_queryset() qs_len = len(queryset) class Resource(resource_class): def __init__(self, *args, **kwargs): self.row_number = 1 super().__init__(*args, **kwargs) def export_resource(self, *args, **kwargs): if self.row_number % 20 == 0 or self.row_number == 1: change_job_status( export_job, "export", "Exporting row %s/%s" % (self.row_number, qs_len), ) self.row_number += 1 return super(Resource, self).export_resource(*args, **kwargs) resource = Resource() data = resource.export(queryset) format = get_format(export_job) serialized = format.export_data(data) change_job_status(export_job, "export", "Export complete") filename = "{app}-{model}-{date}.{extension}".format( app=export_job.app_label, model=export_job.model, date=str(datetime.now()), extension=format.get_extension(), ) if not format.is_binary(): serialized = serialized.encode("utf8") export_job.file.save(filename, ContentFile(serialized)) if export_job.email_on_completion: send_mail( _("Django: Export job completed"), _( "Your export job on model {app_label}.{model} has completed. You can download the file at the following link:\n\n{link}" ).format( app_label=export_job.app_label, model=export_job.model, link=export_job.site_of_origin + reverse( "admin:%s_%s_change" % (export_job._meta.app_label, export_job._meta.model_name,), args=[export_job.pk], ), ), settings.SERVER_EMAIL, [export_job.updated_by.email], ) return