Advertisement
OOPMan

send_mail

Jun 19th, 2014
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. def send_mail(to_address, subject, body, extra_images=None, attachments=[], use_celery=USE_CELERY_FOR_EMAIL):
  2.     """
  3.    TODO: Document this
  4.    """
  5.     images = [('signature-translucent.png', 'signature'), ]
  6.     # redirect emails if necessary
  7.     if USER_EMAIL_REDIRECT:
  8.         subject = '%s (redirected from %s )' % (subject, to_address)
  9.         to_address = USER_EMAIL_REDIRECT
  10.     if extra_images:
  11.         images += extra_images
  12.     try:
  13.         if use_celery:
  14.             send_email_task.delay(to_address, subject, body, images, attachments=attachments, APP_ROOT=APP_ROOT)
  15.         else:
  16.             send_email_thread = Thread(target=send_email, args=[to_address, subject, body, images],
  17.                                        kwargs={'attachments': attachments, 'APP_ROOT': APP_ROOT})
  18.             send_email_thread.start()
  19.     except Exception as e:
  20.         logger.exception("Fatal exception while sending email.\n" + str(e))
  21.         return False
  22.     return True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement