def _send_reminder(self, email_reminder, now, dry_run=False): subject = u"[DoneCal]" if email_reminder.time[0] > 12: about_today = True subject += " What did you do today?" else: about_today = False subject += u" What did you do yesterday?" first_name = email_reminder.user.first_name email_reminder_edit_url = 'http://%s/emailreminders/' % self.request.host if email_reminder.user.premium: email_reminder_edit_url = email_reminder_edit_url\ .replace('http://','https://') hour_example_1 = '14:45' hour_example_2 = '10:30' user_settings = self.get_current_user_settings( user=email_reminder.user) if user_settings and user_settings.ampm_format: hour_example_1 = '2pm' hour_example_2 = '10:30am' summary_events = list() if email_reminder.include_summary: _search = {'user.$id': email_reminder.user._id} # if it was about today, make the search start at 00.00 today _today = datetime.datetime(now.year, now.month, now.day) if about_today: _search['start'] = {'$gte': _today} else: _yesterday = _today - datetime.timedelta(days=1) _search['start'] = {'$gte': _yesterday, '$lt': _today} for event in self.db.Event.find(_search).sort('start', 1): summary_events.append(self._summorize_event(event)) email_reminder_edit_url += '?edit=%s' % email_reminder._id body = self.render_string("emailreminders/send_reminder.txt", email_reminder=email_reminder, first_name=first_name, about_today=about_today, email_reminder_edit_url=\ email_reminder_edit_url, hour_example_1=hour_example_1, hour_example_2=hour_example_2, include_instructions=email_reminder.include_instructions, summary_events=summary_events) from_email = EMAIL_REMINDER_SENDER % {'id': str(email_reminder._id)} from_ = "DoneCal <%s>" % from_email send_email( self.application.settings['email_backend'], subject, body, from_, [email_reminder.user.email], )
def error_reply(self, error_message, msg, body, email_reminder=None): """send an email reply""" if isinstance(body, str): body = unicode(body, 'utf-8') body = body.replace('\r\n', '\n') body = '\n'.join(['> %s' % line for line in body.splitlines()]) body = u'Error in receiving email.\n %s\n\nPlease try again.\n\n' \ % error_message + body subject = "Re: %s" % msg['Subject'] if email_reminder: from_email = EMAIL_REMINDER_SENDER % { 'id': str(email_reminder._id) } else: from_email = EMAIL_REMINDER_NOREPLY from_ = "DoneCal <%s>" % from_email send_email( self.application.settings['email_backend'], subject, body, from_, [msg['From']], )
def _send_reminder(self, email_reminder, now, dry_run=False): subject = u"[DoneCal]" if email_reminder.time[0] > 12: about_today = True subject += " What did you do today?" else: about_today = False subject += u" What did you do yesterday?" first_name = email_reminder.user.first_name email_reminder_edit_url = "http://%s/emailreminders/" % self.request.host if email_reminder.user.premium: email_reminder_edit_url = email_reminder_edit_url.replace("http://", "https://") hour_example_1 = "14:45" hour_example_2 = "10:30" user_settings = self.get_current_user_settings(user=email_reminder.user) if user_settings and user_settings.ampm_format: hour_example_1 = "2pm" hour_example_2 = "10:30am" summary_events = list() if email_reminder.include_summary: _search = {"user.$id": email_reminder.user._id} # if it was about today, make the search start at 00.00 today _today = datetime.datetime(now.year, now.month, now.day) if about_today: _search["start"] = {"$gte": _today} else: _yesterday = _today - datetime.timedelta(days=1) _search["start"] = {"$gte": _yesterday, "$lt": _today} for event in self.db.Event.find(_search).sort("start", 1): summary_events.append(self._summorize_event(event)) email_reminder_edit_url += "?edit=%s" % email_reminder._id body = self.render_string( "emailreminders/send_reminder.txt", email_reminder=email_reminder, first_name=first_name, about_today=about_today, email_reminder_edit_url=email_reminder_edit_url, hour_example_1=hour_example_1, hour_example_2=hour_example_2, include_instructions=email_reminder.include_instructions, summary_events=summary_events, ) from_email = EMAIL_REMINDER_SENDER % {"id": str(email_reminder._id)} from_ = "DoneCal <%s>" % from_email send_email(self.application.settings["email_backend"], subject, body, from_, [email_reminder.user.email])
def _email_exception(self, exception): # pragma: no cover import sys 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) send_email( self.application.settings['email_backend'], subject, out.getvalue(), self.application.settings['webmaster'], self.application.settings['admin_emails'], )
def _email_exception(self, exception): # pragma: no cover import sys 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) send_email( self.application.settings["email_backend"], subject, out.getvalue(), self.application.settings["webmaster"], self.application.settings["admin_emails"], )
def error_reply(self, error_message, msg, body, email_reminder=None): """send an email reply""" if isinstance(body, str): body = unicode(body, "utf-8") body = body.replace("\r\n", "\n") body = "\n".join(["> %s" % line for line in body.splitlines()]) body = u"Error in receiving email.\n %s\n\nPlease try again.\n\n" % error_message + body subject = "Re: %s" % msg["Subject"] if email_reminder: from_email = EMAIL_REMINDER_SENDER % {"id": str(email_reminder._id)} else: from_email = EMAIL_REMINDER_NOREPLY from_ = "DoneCal <%s>" % from_email send_email(self.application.settings["email_backend"], subject, body, from_, [msg["From"]])
def send_successful_update_letter(user): """ Function that provides sending successful update letter. :param user: user that we want send letter to. :type user: UserProfile obj :return: True if letter was send else None. """ ctx = {'first_name': user.first_name or user.email} subject = 'Password reset' message = 'Successful password reset.' recipient_list = [user.email] templates = 'update_password.html' if send_email(subject, message, recipient_list, templates, ctx): return True return False
def send_password_update_letter(user, token): """ Function that provides sending update password letter to user. :param user: user that we want send letter to. :type user: UserProfile obj :return: True if letter was send else None. """ ctx = { 'first_name': user.first_name or user.email, 'token': token, 'domain': FRONT_HOST, 'time_left': USER_TTL_NOTIFICATOR } subject = 'Password reset' message = 'You tried to change your password.' recipient_list = [user.email] templates = 'change_password_link.html' if send_email(subject, message, recipient_list, templates, ctx): return True return False
def tsend_email(): url = "http://1000phone.com" receiver = '*****@*****.**' content = pack_html(receiver, url) send_email(receiver, content) print('send email ok!')
from utils.HTMLTestRunner import HTMLTestRunner import time import os from utils.send_mail import send_email test_dir = './test/test_case' #定义discover 方法的参数 discover = unittest.defaultTestLoader.discover(test_dir, pattern='test_*.py', top_level_dir=None) if __name__ == "__main__": # 获取当前时间 now = time.strftime("%Y-%m-%d %H_%M_%S", time.localtime(time.time())) # 定义个报告存放路径 path = os.path.dirname(os.path.abspath(__file__)) path1 = path.replace('\\', '/') filename = path1 + "/report/" + now + "result.html" print(filename) fp = open(filename, 'wb') # 定义测试报告 runner = HTMLTestRunner(stream=fp, title=u'自动化测试报告', description=u'用例执行情况:') # 运行测试用例 runner.run(discover) # 关闭报告文件 fp.close() # 发送邮件 send_email(filename)