app/soc/logic/mail_dispatcher.py
changeset 1545 ce5d37a38091
parent 1449 9d2e46122b36
child 1548 15caebd3304d
equal deleted inserted replaced
1544:5d23f0160fcd 1545:ce5d37a38091
   114   message = mail.EmailMessage(**context)
   114   message = mail.EmailMessage(**context)
   115   message.check_initialized()
   115   message.check_initialized()
   116 
   116 
   117   # send the message
   117   # send the message
   118   message.send()
   118   message.send()
       
   119 
       
   120 def getDefaultMailSender():
       
   121   """Returns the email address that currently can be used to send emails.
       
   122   
       
   123   Returns:
       
   124     - If available the noreply email address from the site singleton
       
   125     - Or the email address of the current logged in User
       
   126     - None if there is no address to return
       
   127   """
       
   128 
       
   129   import logging
       
   130 
       
   131   from google.appengine.api import users
       
   132 
       
   133   from soc.logic.models import site as site_logic
       
   134 
       
   135 
       
   136   site_entity = site_logic.logic.getSingleton()
       
   137 
       
   138   if site_entity.noreply_email:
       
   139     return site_entity.noreply_email
       
   140 
       
   141   # use the email address of the current logged in user
       
   142   account_entity = users.get_current_user()
       
   143 
       
   144   if not account_entity:
       
   145     logging.warning('Non-Authenticated user triggered getDefaultMailSender')
       
   146     return None
       
   147 
       
   148   return account_entity.email()