def send_url(url, fileid, recipient, debug=False): if debug: backend = 'tornado_utils.send_mail.backends.console.EmailBackend' else: backend = 'tornado_utils.send_mail.backends.smtp.EmailBackend' from_ = 'HUGEPic <*****@*****.**>' % fileid subject = "Your HUGE upload has finished" body = ( "Hi,\n" "\n" "The wonderful picture you uploaded is now fully processed.\n" "\n" "You can view at:\n" "\t" + url + "\n\n" "--\n" "HUGEpic.io" ) send_email( backend, subject, body, from_, [recipient], bcc=getattr(settings, 'BCC_EMAIL', None) )
def post(self, _id): feedback = self.db.Feedback.find_one({'_id': ObjectId(_id)}) post_data = djangolike_request_dict(self.request.arguments) form = FeedbackReplyForm(post_data) if form.validate(): current_user = self.get_current_user() reply = self.db.Feedback() reply['user'] = current_user['_id'] reply['reply_to'] = feedback['_id'] reply['comment'] = form.comment.data reply['what'] = u'reply' reply.save() self.set_header('Content-Type', 'text/plain') body = self.render_string( "admin/feedback_reply.txt", **{ 'feedback': feedback, 'feedback_location': (self.db.Location.find_one({'_id': feedback['location']})), 'reply': reply, 'reply_user': current_user, }) if feedback.get('email'): email = feedback['email'] else: user = self.db.User.find_one({'_id': feedback['user']}) email = user['email'] if email: subject = ("Reply to your feedback on %s" % settings.PROJECT_TITLE) send_email( self.application.settings['email_backend'], subject, body, current_user['email'], [email], ) self.push_flash_message("Email sent!", "Sent to %s" % email, type_='success') url = self.reverse_url('admin_feedback_reply', feedback['_id']) self.redirect(url) else: self.get(_id, form=form)
def _notify_about_new_user(self, user, extra_message=None): subject = "New user!" email_body = "%s %s\n" % (user.first_name, user.last_name) email_body += "%s\n" % user.email if extra_message: email_body += '%s\n' % extra_message send_email(self.application.settings['email_backend'], subject, email_body, self.application.settings['webmaster'], self.application.settings['admin_emails'], )
def _email_exception(self, exception): # pragma: no cover import sys from pprint import pprint err_type, err_val, err_traceback = sys.exc_info() error = u'%s: %s' % (err_type, err_val) out = StringIO() subject = "%r on %s" % (err_val, self.request.path) print >>out, "TRACEBACK:" traceback.print_exception(err_type, err_val, err_traceback, 500, out) traceback_formatted = out.getvalue() print traceback_formatted print >>out, "\nREQUEST ARGUMENTS:" arguments = self.request.arguments if arguments.get('password') and arguments['password'][0]: password = arguments['password'][0] arguments['password'] = password[:2] + '*' * (len(password) -2) pprint(arguments, out) print >>out, "\nCOOKIES:" for cookie in self.cookies: print >>out, " %s:" % cookie, print >>out, repr(self.get_secure_cookie(cookie)) print >>out, "\nREQUEST:" for key in ('full_url', 'protocol', 'query', 'remote_ip', 'request_time', 'uri', 'version'): print >>out, " %s:" % key, value = getattr(self.request, key) if callable(value): try: value = value() except: pass print >>out, repr(value) print >>out, "\nGIT REVISION: ", print >>out, self.application.settings['git_revision'] print >>out, "\nHEADERS:" pprint(dict(self.request.headers), out) try: send_email(self.application.settings['email_backend'], subject, out.getvalue(), self.application.settings['webmaster'], settings.DEVELOPER_EMAILS, ) except: logging.error("Failed to send email", exc_info=True)
def send_feedback(document, debug=False): from_ = 'HUGEPic <*****@*****.**>' subject = "Feedback on HUGEpic" body = '' for key in ('name', 'email', 'type', 'comment', 'current_user'): body += '%s: %s\n' % (key.capitalize(), document.get(key, '--')) body += 'Date: %s\n' % datetime.datetime.utcnow() send_email( _get_backend(debug), subject, body, from_, [settings.ADMIN_EMAILS[0]], )
def _notify_about_new_user(self, user, extra_message=None): subject = "New user!" email_body = "%s %s\n" % (user.first_name, user.last_name) email_body += "%s\n" % user.email if extra_message: email_body += '%s\n' % extra_message send_email( self.application.settings['email_backend'], subject, email_body, self.application.settings['webmaster'], self.application.settings['admin_emails'], )
def _email_exception(self, exception): # pragma: no cover import sys from pprint import pprint err_type, err_val, err_traceback = sys.exc_info() error = u'%s: %s' % (err_type, err_val) out = StringIO() subject = "%r on %s" % (err_val, self.request.path) print >> out, "TRACEBACK:" traceback.print_exception(err_type, err_val, err_traceback, 500, out) traceback_formatted = out.getvalue() print traceback_formatted print >> out, "\nREQUEST ARGUMENTS:" arguments = self.request.arguments if arguments.get('password') and arguments['password'][0]: password = arguments['password'][0] arguments['password'] = password[:2] + '*' * (len(password) - 2) pprint(arguments, out) print >> out, "\nCOOKIES:" for cookie in self.cookies: print >> out, " %s:" % cookie, print >> out, repr(self.get_secure_cookie(cookie)) print >> out, "\nREQUEST:" for key in ('full_url', 'protocol', 'query', 'remote_ip', 'request_time', 'uri', 'version'): print >> out, " %s:" % key, value = getattr(self.request, key) if callable(value): try: value = value() except: pass print >> out, repr(value) print >> out, "\nGIT REVISION: ", print >> out, self.application.settings['git_revision'] print >> out, "\nHEADERS:" pprint(dict(self.request.headers), out) try: send_email( self.application.settings['email_backend'], subject, out.getvalue(), self.application.settings['webmaster'], settings.DEVELOPER_EMAILS, ) except: logging.error("Failed to send email", exc_info=True)
def _email_exception(self, status_code, err_type, err_val, err_traceback): import traceback from cStringIO import StringIO from pprint import pprint out = StringIO() subject = "%r on %s" % (err_val, self.request.path) out.write("TRACEBACK:\n") traceback.print_exception(err_type, err_val, err_traceback, 500, out) traceback_formatted = out.getvalue() #print traceback_formatted out.write("\nREQUEST ARGUMENTS:\n") arguments = self.request.arguments if arguments.get('password') and arguments['password'][0]: password = arguments['password'][0] arguments['password'] = password[:2] + '*' * (len(password) -2) pprint(arguments, out) out.write("\nCOOKIES:\n") for cookie in self.cookies: out.write("\t%s: " % cookie) out.write("%r\n" % self.get_secure_cookie(cookie)) out.write("\nREQUEST:\n") for key in ('full_url', 'protocol', 'query', 'remote_ip', 'request_time', 'uri', 'version'): out.write(" %s: " % key) value = getattr(self.request, key) if callable(value): try: value = value() except: pass out.write("%r\n" % value) out.write("\nHEADERS:\n") pprint(dict(self.request.headers), out) try: send_email(self.application.settings['email_backend'], subject, out.getvalue(), self.application.settings['admin_emails'][0], self.application.settings['admin_emails'], ) except: logging.error("Failed to send email", exc_info=True)
def _email_exception(self, status_code, err_type, err_val, err_traceback): import traceback from cStringIO import StringIO from pprint import pprint out = StringIO() subject = "%r on %s" % (err_val, self.request.path) out.write("TRACEBACK:\n") traceback.print_exception(err_type, err_val, err_traceback, 500, out) traceback_formatted = out.getvalue() #print traceback_formatted out.write("\nREQUEST ARGUMENTS:\n") arguments = self.request.arguments if arguments.get('password') and arguments['password'][0]: password = arguments['password'][0] arguments['password'] = password[:2] + '*' * (len(password) - 2) pprint(arguments, out) out.write("\nCOOKIES:\n") for cookie in self.cookies: out.write("\t%s: " % cookie) out.write("%r\n" % self.get_secure_cookie(cookie)) out.write("\nREQUEST:\n") for key in ('full_url', 'protocol', 'query', 'remote_ip', 'request_time', 'uri', 'version'): out.write(" %s: " % key) value = getattr(self.request, key) if callable(value): try: value = value() except: pass out.write("%r\n" % value) out.write("\nHEADERS:\n") pprint(dict(self.request.headers), out) try: send_email( self.application.settings['email_backend'], subject, out.getvalue(), self.application.settings['admin_emails'][0], self.application.settings['admin_emails'], ) except: logging.error("Failed to send email", exc_info=True)
def post(self, _id): feedback = self.db.Feedback.find_one({"_id": ObjectId(_id)}) post_data = djangolike_request_dict(self.request.arguments) form = FeedbackReplyForm(post_data) if form.validate(): current_user = self.get_current_user() reply = self.db.Feedback() reply["user"] = current_user["_id"] reply["reply_to"] = feedback["_id"] reply["comment"] = form.comment.data reply["what"] = u"reply" reply.save() self.set_header("Content-Type", "text/plain") body = self.render_string( "admin/feedback_reply.txt", **{ "feedback": feedback, "feedback_location": (self.db.Location.find_one({"_id": feedback["location"]})), "reply": reply, "reply_user": current_user, } ) if feedback.get("email"): email = feedback["email"] else: user = self.db.User.find_one({"_id": feedback["user"]}) email = user["email"] if email: subject = "Reply to your feedback on %s" % settings.PROJECT_TITLE send_email(self.application.settings["email_backend"], subject, body, current_user["email"], [email]) self.push_flash_message("Email sent!", "Sent to %s" % email, type_="success") url = self.reverse_url("admin_feedback_reply", feedback["_id"]) self.redirect(url) else: self.get(_id, form=form)
def send_email_verification(self, user, email): user_settings = self.get_user_settings(user) if not user_settings: user_settings = self.create_user_settings(user) add_date_ts = mktime(user.add_date.timetuple()) tag = '%s-%s' % (email, add_date_ts) hash = md5(tag).hexdigest() url = '%s://%s' % (self.request.protocol, self.request.host) url += self.reverse_url('verify_email', user._id, hash) options = { 'url': url, 'user': user, 'email': email, } body = self.render_string('user/verify-email.txt', **options) send_email( self.application.settings['email_backend'], "Kwissle email verification", body, self.application.settings['webmaster'], [email], )
def send_email_verification(self, user, email): user_settings = self.get_user_settings(user) if not user_settings: user_settings = self.create_user_settings(user) add_date_ts = mktime(user.add_date.timetuple()) tag = '%s-%s' % (email, add_date_ts) hash = md5(tag).hexdigest() url = '%s://%s' % (self.request.protocol, self.request.host) url += self.reverse_url('verify_email', user._id, hash) options = { 'url': url, 'user': user, 'email': email, } body = self.render_string('user/verify-email.txt', **options) send_email(self.application.settings['email_backend'], "Kwissle email verification", body, self.application.settings['webmaster'], [email], )
def run(options): db = connection[settings.DATABASE_NAME] only_email_addresses = options.only_email_addresses only_email_addresses = [ x.strip() for x in only_email_addresses.split(',') if x.strip() ] subject = options.subject template_filename = os.path.abspath(os.path.normpath(options.messagetemplate)) template_code = open(template_filename).read() template = tornado.template.Template(template_code) log_filename = options.messagetemplate + '.log' try: done_user_ids = [ x.strip() for x in open(log_filename).read().splitlines() if x.strip() ] except IOError: done_user_ids = [] unsubscribers = [ x['user'] for x in db.UserSettings.find({'unsubscribe_emails': True}, ('user',)) ] _locations = {} for user in db.User.find({'email': {'$ne': None}}): if not user['email'] or user['_id'] in unsubscribers: continue if str(user['_id']) in done_user_ids: print "Skipping", user['email'] continue if only_email_addresses: if user['email'] in only_email_addresses: print "ONLY", user['email'] else: continue if user['current_location'] not in _locations: _locations[user['current_location']] = ( db.Location.find_one({'_id': user['current_location']}) ) user_settings = db.UserSettings.find_one({'user': user['_id']}) assert user_settings data = { 'SIGNATURE': settings.SIGNATURE, 'user': user, 'user_settings': user_settings, 'current_location': _locations[user['current_location']], 'unsubscribe_uri': '/unsubscribe/%s' % user.tokenize_id(user['_id'], 12) } body = template.generate(**data) if options.dry_run: email_backend = 'tornado_utils.send_mail.backends.console.EmailBackend' else: email_backend = 'tornado_utils.send_mail.backends.pickle.EmailBackend' send_email( email_backend, subject, body, "Around The World <*****@*****.**>",#settings.ADMIN_EMAILS[0], #"Around The World <%s>" % settings.ADMIN_EMAILS[0], [user['email']], ) if not options.dry_run: open(log_filename, 'a').write('%s\n' % user['_id']) else: print "emailed", user['email']