Catch mail exceptions and use get_current_user
authorSverre Rabbelier <srabbelier@gmail.com>
Sat, 28 Feb 2009 14:28:28 +0000
changeset 1560 656aace0b15f
parent 1559 283046e54c01
child 1561 fe1b141bfc2c
Catch mail exceptions and use get_current_user Patch by: Sverre Rabbelier
app/soc/logic/helper/notifications.py
app/soc/logic/mail_dispatcher.py
--- a/app/soc/logic/helper/notifications.py	Sat Feb 28 13:06:04 2009 +0000
+++ b/app/soc/logic/helper/notifications.py	Sat Feb 28 14:28:28 2009 +0000
@@ -224,7 +224,7 @@
     # no valid sender found, should not happen but abort anyway
     return
   else:
-    (sender_name, sender) = default_sender
+    sender_name, sender = default_sender
 
   to = accounts.denormalizeAccount(user_entity.account).email()
 
--- a/app/soc/logic/mail_dispatcher.py	Sat Feb 28 13:06:04 2009 +0000
+++ b/app/soc/logic/mail_dispatcher.py	Sat Feb 28 14:28:28 2009 +0000
@@ -67,6 +67,7 @@
 from django.template import loader
 
 from google.appengine.api import mail
+from google.appengine.api import users
 
 from soc.logic import dicts
 
@@ -114,8 +115,13 @@
   message = mail.EmailMessage(**context)
   message.check_initialized()
 
-  # send the message
-  message.send()
+  try:
+    # send the message
+    message.send()
+  except Exception, e:
+    import logging
+    logging.info(context)
+    logging.exception(e)
 
 def getDefaultMailSender():
   """Returns the sender that currently can be used to send emails.
@@ -141,13 +147,14 @@
     return (site_entity.site_name, site_entity.noreply_email)
 
   # use the email address of the current logged in user
-  user_entity = user_logic.logic.getForCurrentAccount()
+  account = users.get_current_user()
 
-  if not user_entity:
+  # we need to retrieve account seperately, as user_logic normalizes it
+  # and the GAE admin API is case sensitive
+  user_entity = user_logic.logic.getForAccount(account)
+
+  if not account:
     logging.warning('Non-Authenticated user triggered getDefaultMailSender')
     return None
 
-  # denormalize the account and retrieve the email
-  sender = accounts.denormalizeAccount(user_entity.account).email()
-
-  return (user_entity.name, sender)
+  return (user_entity.name, account.email())