def get(self): time_notification = 120 # Email notification when time left is no more than 2 hours current_time = datetime.datetime.now() sections = model.Section.query().fetch() for section in sections: print section.name num = utils.get_current_round(section) if num: rounds = model.Round.query(ancestor=section.key).fetch() for rnd in rounds: if rnd.number == num: round = rnd break delta_time = round.deadline - current_time time_remaining = 24 * 60 * delta_time.days + delta_time.seconds // 60 if 0 < time_remaining < time_notification: sec_emails = [s.email for s in section.students] response = model.Response.query(ancestor=round.key).fetch() res_emails = [res.student for res in response] to_emails = [ email for email in sec_emails if email not in res_emails ] email_message = 'Dear Students: \n' \ 'No more than 30 minutes left to submit your answer.' \ 'Please finish it as soon as possible! \n' \ 'Best,\n' \ 'Consider Team\n' utils.send_mails(to_emails, "CONSIDER: Deadline Approaching", email_message) self.redirect('/')
def notify_update(self): ctype = ContentType.objects.get_for_model(self) subscribers = Subscriptions.objects.filter(content_type=ctype, object_id=self.id) subject = 'Updates on mloss.org software project ' + self.title message = '''Dear mloss.org user, you are receiving this email as you have subscribed to the "''' message += self.title message += '''" software project, which has just been updated. Feel free to visit mloss.org to see what has changed. ''' message += 'http://%s%s' % (Site.objects.get_current().domain, self.get_absolute_url()) message += ''' Friendly, your mloss.org team. ''' send_mails(subscribers, subject, message)
def comment_notification(**kwargs): """ instance is the comment object """ sender = kwargs['sender'] comment = kwargs['comment'] try: sw = comment.content_object ctype = ContentType.objects.get_for_model(sw) subscribers = Subscriptions.objects.filter(content_type=ctype, object_id=sw.id) if ctype.name and ctype.name == u'software': subject = 'New comment on mloss.org software project ' + sw.title message = '''Dear mloss.org user, you are receiving this email as you have subscribed to the "''' message += sw.title message += '''" software project, for which a new comment has just been posted. Feel free to visit mloss.org to see what has changed. ''' else: return # no comment notification for objects other than software yet message += 'http://%s%s' % (Site.objects.get_current().domain, comment.get_absolute_url()) message += ''' Friendly, your mloss.org team. ''' send_mails(subscribers, subject, message) except ObjectDoesNotExist: pass
def comment_notification(**kwargs): """ instance is the comment object """ sender=kwargs['sender'] comment=kwargs['comment'] try: sw=comment.content_object ctype = ContentType.objects.get_for_model(sw) subscribers=Subscriptions.objects.filter(content_type=ctype, object_id=sw.id) if ctype.name and ctype.name == u'software': subject='New comment on mloss.org software project ' + sw.title message='''Dear mloss.org user, you are receiving this email as you have subscribed to the "''' message+=sw.title message+='''" software project, for which a new comment has just been posted. Feel free to visit mloss.org to see what has changed. ''' else: return # no comment notification for objects other than software yet message+='http://%s%s' % (Site.objects.get_current().domain, comment.get_absolute_url()) message+=''' Friendly, your mloss.org team. ''' send_mails(subscribers, subject, message) except ObjectDoesNotExist: pass
def notify_update(self): ctype = ContentType.objects.get_for_model(self) subscribers=Subscriptions.objects.filter(content_type=ctype, object_id=self.id) subject='Updates on mloss.org community forum ' + self.title message='''Dear mloss.org user, you are receiving this email as you have subscribed to the "''' message+=self.title message+='''" community forum, which has just been updated. Feel free to visit mloss.org to see what has changed. ''' message+='http://%s%s' % (Site.objects.get_current().domain, self.get_absolute_url()) message+=''' Friendly, your mloss.org team. ''' send_mails(subscribers, subject, message)
result = None content = None request_body = None if category == 'web': if test_type == 'status_code': status_code = sys.argv[5] result = verify_web_status_code(url, status_code) elif test_type == 'content': content = sys.argv[5] result = verify_web_content(url, content) else: utils.log_to_file('test type invalid') elif category == 'service': request_body = sys.argv[6] if test_type == 'status_code': status_code = sys.argv[5] result = verify_service_status_code(url, request_body, status_code) elif test_type == 'content': content = sys.argv[5] result = verify_service_content(url, request_body, content) else: utils.log_to_file('category is invalid') # write result to respective results file if not result is None: write_result(task_id, result) if result == 0: utils.send_mails(task_id)
from utils import send_mails # title - email subject # text-file - txt file with email body # mails_file - txt file with emails seperated with commas # attachment_files - list of filenames to attach ["filename1.pdf, "filename2.pdf"] # sender - email that emails will be sent from # password - email password # all files have to be withing the script directory title = "Job application" text_file = "cover_letter.txt" mails_file = "all_test.txt" attachment_files = ["CV.pdf", "CV.pdf"] sender = "*****@*****.**" password = "******" send_mails(title, text_file, mails_file, attachment_files, sender, password)