Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

+= use send_mail_to_admins if recipient admins@APP-ID.appspotmail.com #54

Open
wants to merge 1 commit into
base: appengine-1.4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions djangoappengine/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,41 @@
from django.core.mail import EmailMultiAlternatives
from django.core.exceptions import ImproperlyConfigured

from google.appengine.api.app_identity import get_application_id
from google.appengine.api import mail as aeemail
from google.appengine.runtime import apiproxy_errors

def _check_for_app_admins(message):
# "admins@APP-ID.appspotmail.com"
# ignore multiple admins adresses...
for to in message.to:
if 'admins@%s.appspotmail.com' % get_application_id() in to or '<admins@%s.appspotmail.com>' % get_application_id() in to:
return True

def _send_app_admins(message):
kw = {}

# kw['to'] = message.to => unused warning
# those sould be empty
# kw['cc'] = message.cc
# kw['bcc'] = message.bcc
if hasattr(message, 'reply_to'):
kw['reply_to'] = message.reply_to
if hasattr(message, 'html'):
kw['html'] = message.html
if hasattr(message, 'attachments'):
kw['attachments'] = message.attachments
if hasattr(message, 'headers'):
kw['headers'] = message.headers

aeemail.send_mail_to_admins(message.sender, message.subject, message.body, **kw)

def _send_deferred(message, fail_silently=False):
try:
message.send()
if _check_for_app_admins(message):
_send_app_admins(message)
else:
message.send()
except (aeemail.Error, apiproxy_errors.Error):
if not fail_silently:
raise
Expand Down Expand Up @@ -71,7 +99,10 @@ def _send(self, message):
self._defer_message(message)
return True
try:
message.send()
if _check_for_app_admins(message):
_send_app_admins(message)
else:
message.send()
except (aeemail.Error, apiproxy_errors.Error):
if not self.fail_silently:
raise
Expand Down