def SendEmail(self): # Get Send Email data contentLength = int(self.headers.get("Content-Length", 0)) body = self.rfile.read(contentLength) data = json.loads(body) sendEmailFile = Expand(r'[Temp]\WebServer.SendEmail.body.htm') self.log_message('SendEmail %s', sendEmailFile) file = open(sendEmailFile, 'w') file.write(data["body"]) file.close() email.send_email(To=[data["to"]], Subject=data["subject"], Body=data["body"], BodyFile="", Silent=False, Strict=True) # Send Response self.send_header('Content-type', 'text/plain') self.send_header('Access-Control-Allow-Origin', '*') self.send_response(200) self.end_headers() self.wfile.write(b'OK')
def ext_appr_cron(request): """ Alert mail for External approval of a project though python cron job """ alert_on = settings.ALERT_ON alert_reminder = settings.ALERT_REMINDER projects = Project.objects.filter(ex_approval=False, is_approved=True, is_active=True).exclude(cancel=True) projects = projects.filter(schedules__approved_date__lt = datetime.datetime.now().date() - relativedelta(days=alert_on)) flag = False for pjt in projects: alerttime_details = ProjectAlertTime.objects.filter(record_id=pjt.id) if len(alerttime_details) > 0: last_alert_with_days = alerttime_details[0].raised_on + relativedelta(days=alert_reminder) if datetime.datetime.now().date() >= last_alert_with_days: alerttime_details.update(raised_on=datetime.datetime.now().date()) flag = True else: alert_time = ProjectAlertTime(record_id=pjt.id, raised_on=datetime.datetime.now().date()) alert_time.save() flag = True if flag: user = User.objects.get(id = pjt.approved_by.id) recipients = user.email # recipients = '*****@*****.**' approved_by = str(User.objects.get(id = pjt.approved_by.id).username) project_name = str(pjt.name) user_name = str(User.objects.get(id = pjt.requested_by.id).username) request_date = str(pjt.schedules.initiation_request_date) delay_days = str((datetime.datetime.now().date() - pjt.schedules.approved_date).days) print 'delay_days', delay_days email_subject = "Need customer approval for " + project_name +" project" mail_content =" <html lang='en'><p>Dear "+approved_by +"<br/><br/> The project " mail_content += project_name +" has not yet got customer approval and is active for past "+ delay_days +" days." mail_content += "</p><br/>Thanks.</html>" try: Email().send_email(email_subject, mail_content, [recipients], CONTENT_TYPE) msg = ' Alert mail for project approval' except Exception: errMessage = 'Email Sending failed \n %s' % (Exception)
def Email_UnitTest(): Trace() email.send_email(To=[Globals.To], Subject='UnitTest: Email_UnitTest Subject [Date] - [COMPUTERNAME]', Body='Hi', Attachments=Path(r'[TestDataFolder]\File2.txt'), Strict=True) UnitTest.Verify(True, 'Sent Email')