def send_enroll_form_to_admin(request,test_id=None): logging.info(request.POST) if not cfg.getConfigBool('ENROLL_FORM_EMAIL_ON',False): logging.info('ENROLL_FORM_EMAIL_ON is OFF!') return HttpResponse('ok - disabled') if test_id is None: student_id = request.POST['student_id'] else: student_id = test_id student = Student.get_by_id(int(student_id)) if student is None: raise Http404 logging.info('student=%s'%student) course = student.get_course() partner = student.get_partner() logging.info('course=%s'%(course)) sender = cfg.getConfigString('ENROLL_FORM_EMAIL_SENDER',None) to = cfg.getConfigString('ENROLL_FORM_EMAIL_TO',None) if sender is None: logging.info('no sender') return HttpResponse('ok - no sender, ignore') if to is None: logging.info('no to') return HttpResponse('ok - no to, ignore') logging.info('prepare text') (subject,body) = mail.prepare_email_text('ENROLL_FORM_REPORT', student,course,partner) logging.info('prepare text done') # subject = "online prihlaska" #cfg.getConfigString('ENROLL_FORM_EMAIL_SUBJECT',None) # body = "online prihlaska je v priloze" #cfg.getConfigString('ENROLL_FORM_EMAIL_SUBJECT',None) filename = "prihlaska.pdf" out = cStringIO.StringIO() from utils.pdf import students_enroll students_enroll(out,[student],with_partner=True) data=out.getvalue() gmail.send_mail(sender=sender, to=to,subject=subject,body=body,attachments=[(filename,data)]) logging.info('send ok') return HttpResponse('ok')
def send_student_email(request): logging.info(request.POST) student_id = request.POST['student_id'] student = Student.get_by_id(int(student_id)) if student is None: logging.info('student is None') raise Http404 logging.info('student=%s'%(student)) course = student.get_course() partner = student.get_partner() logging.info('course=%s'%(course)) template_key = request.POST['template_key'] if template_key is None: logging.info('template_key is None') raise Http404 logging.info('template_key=%s'%(template_key)) if not template_key in mail.MAIL_TEMPLATE_KEYS: logging.info('template_key is not valid') raise Http404 logging.info('key ok') sender = cfg.getConfigString('ENROLL_EMAIL',None) reply_to = cfg.getConfigString('ENROLL_REPLY_TO',None) bcc = cfg.getConfigString('ENROLL_BCC',None) if sender is None: logging.info('no sender, skip') return HttpResponse('ok') if reply_to is None: logging.info('no reply to !, skip') return HttpResponse('ok') if not mail.valid_email(student.email): logging.info('no valid student email') return HttpResponse('ok') recipient = student.email.__str__() logging.info('prepare text') (subject,body) = mail.prepare_email_text(template_key, student,course,partner) logging.info('prepare text done') # sss=unicode(body,'utf-8') # logging.info(type(subject)) # logging.info(sss) # logging.info(body.encode('utf8')) logging.info('sender [%s]'%(sender)) logging.info('reply_to [%s]'%(sender)) logging.info('recipient [%s]'%(recipient)) if not (bcc is None): logging.info('bcc [%s]'%(bcc)) if bcc is None: logging.info('no bcc !, ignore bcc header') gmail.send_mail(sender=sender, reply_to=reply_to, to=recipient, subject=subject,body=body) else: gmail.send_mail(sender=sender, reply_to=reply_to, bcc=bcc, to=recipient, subject=subject,body=body) logging.info('sent out !') return HttpResponse('ok')