def send_beans_email(to_address, username, beans): email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return #text = 'Dear '+ username + ':\n' + ' Your beans in docklet are less than' + beans + '.' text = '<html><h4>Dear '+ username + ':</h4>' text += '''<p> Your beans in <a href='%s'>docklet</a> are %d now. </p> <p> If your beans are less than or equal to 0, all your worksapces will be stopped.</p> <p> Please apply for more beans to keep your workspaces running by following link:</p> <p> <a href='%s/beans/application/'>%s/beans/application/</p> <br> <p> Note: DO NOT reply to this email!</p> <br><br> <p> <a href='http://docklet.unias.org'>Docklet Team</a>, SEI, PKU</p> ''' % (env.getenv("PORTAL_URL"), beans, env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL")) text += '<p>'+ str(datetime.datetime.now()) + '</p>' text += '</html>' subject = 'Docklet beans alert' msg = MIMEMultipart() textmsg = MIMEText(text,'html','utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = to_address msg.attach(textmsg) s = smtplib.SMTP() s.connect() s.sendmail(email_from_address, to_address, msg.as_string()) s.close()
def send_beans_email(to_address, username, beans): email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return #text = 'Dear '+ username + ':\n' + ' Your beans in docklet are less than' + beans + '.' text = '<html><h4>Dear ' + username + ':</h4>' text += '''<p> Your beans in <a href='%s'>docklet</a> are %d now. </p> <p> If your beans are less than or equal to 0, all your worksapces will be stopped.</p> <p> Please apply for more beans to keep your workspaces running by following link:</p> <p> <a href='%s/beans/application/'>%s/beans/application/</p> <br> <p> Note: DO NOT reply to this email!</p> <br><br> <p> <a href='http://docklet.unias.org'>Docklet Team</a>, SEI, PKU</p> ''' % (env.getenv("PORTAL_URL"), beans, env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL")) text += '<p>' + str(datetime.datetime.now()) + '</p>' text += '</html>' subject = 'Docklet beans alert' msg = MIMEMultipart() textmsg = MIMEText(text, 'html', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = to_address msg.attach(textmsg) s = smtplib.SMTP() s.connect() s.sendmail(email_from_address, to_address, msg.as_string()) s.close()
def send_activated_email(to_address, username): email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return #text = 'Dear '+ username + ':\n' + ' Your account in docklet has been activated' text = '<html><h4>Dear ' + username + ':</h4>' text += '''<p> Your account in <a href='%s'>%s</a> has been activated</p> <p> Enjoy your personal workspace in the cloud !</p> <br> <p> Note: DO NOT reply to this email!</p> <br><br> <p> <a href='http://docklet.unias.org'>Docklet Team</a>, SEI, PKU</p> ''' % (env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL")) text += '<p>' + str(datetime.now()) + '</p>' text += '</html>' subject = 'Docklet account activated' msg = MIMEMultipart() textmsg = MIMEText(text, 'html', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = to_address msg.attach(textmsg) s = smtplib.SMTP() s.connect() s.sendmail(email_from_address, to_address, msg.as_string()) s.close()
def send_activated_email(to_address, username): email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return #text = 'Dear '+ username + ':\n' + ' Your account in docklet has been activated' text = '<html><h4>Dear '+ username + ':</h4>' text += '''<p> Your account in <a href='%s'>%s</a> has been activated</p> <p> Enjoy your personal workspace in the cloud !</p> <br> <p> Note: DO NOT reply to this email!</p> <br><br> <p> <a href='http://docklet.unias.org'>Docklet Team</a>, SEI, PKU</p> ''' % (env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL")) text += '<p>'+ str(datetime.now()) + '</p>' text += '</html>' subject = 'Docklet account activated' msg = MIMEMultipart() textmsg = MIMEText(text,'html','utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = to_address msg.attach(textmsg) s = smtplib.SMTP() s.connect() s.sendmail(email_from_address, to_address, msg.as_string()) s.close()
def send_bug_mail(username, bugmessage): #admin_email_address = env.getenv('ADMIN_EMAIL_ADDRESS') nulladdr = ['\'\'', '\"\"', ''] email_from_address = settings.get('EMAIL_FROM_ADDRESS') admin_email_address = settings.get('ADMIN_EMAIL_ADDRESS') logger.info("receive bug from %s: %s" % (username, bugmessage)) if (email_from_address in nulladdr or admin_email_address in nulladdr): return {'success': 'false'} #text = 'Dear '+ username + ':\n' + ' Your account in docklet has been activated' text = '<html><h4>Dear ' + 'admin' + ':</h4>' text += '''<p> A bug has been report by %s.</p> <br/> <strong> %s </strong> <br/> <p> Please check it !</p> <br/><br/> <p> Docklet Team, SEI, PKU</p> ''' % (username, bugmessage) text += '<p>' + str(datetime.utcnow()) + '</p>' text += '</html>' subject = 'A bug of Docklet has been reported' if admin_email_address[0] == '"': admins_addr = admin_email_address[1:-1].split(" ") else: admins_addr = admin_email_address.split(" ") alladdr = "" for addr in admins_addr: alladdr = alladdr + addr + ", " alladdr = alladdr[:-2] msg = MIMEMultipart() textmsg = MIMEText(text, 'html', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = alladdr msg.attach(textmsg) s = smtplib.SMTP() s.connect() try: s.sendmail(email_from_address, admins_addr, msg.as_string()) except Exception as e: logger.error(e) s.close() return {'success': 'true'}
def send_bug_mail(username, bugmessage): #admin_email_address = env.getenv('ADMIN_EMAIL_ADDRESS') nulladdr = ['\'\'', '\"\"', ''] email_from_address = settings.get('EMAIL_FROM_ADDRESS') admin_email_address = settings.get('ADMIN_EMAIL_ADDRESS') logger.info("receive bug from %s: %s" % (username, bugmessage)) if (email_from_address in nulladdr or admin_email_address in nulladdr): return {'success': 'false'} #text = 'Dear '+ username + ':\n' + ' Your account in docklet has been activated' text = '<html><h4>Dear '+ 'admin' + ':</h4>' text += '''<p> A bug has been report by %s.</p> <br/> <strong> %s </strong> <br/> <p> Please check it !</p> <br/><br/> <p> Docklet Team, SEI, PKU</p> ''' % (username, bugmessage) text += '<p>'+ str(datetime.utcnow()) + '</p>' text += '</html>' subject = 'A bug of Docklet has been reported' if admin_email_address[0] == '"': admins_addr = admin_email_address[1:-1].split(" ") else: admins_addr = admin_email_address.split(" ") alladdr="" for addr in admins_addr: alladdr = alladdr+addr+", " alladdr=alladdr[:-2] msg = MIMEMultipart() textmsg = MIMEText(text,'html','utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = alladdr msg.attach(textmsg) s = smtplib.SMTP() s.connect() try: s.sendmail(email_from_address, admins_addr, msg.as_string()) except Exception as e: logger.error(e) s.close() return {'success':'true'}
def send_remind_activating_email(username): #admin_email_address = env.getenv('ADMIN_EMAIL_ADDRESS') nulladdr = ['\'\'', '\"\"', ''] email_from_address = settings.get('EMAIL_FROM_ADDRESS') admin_email_address = settings.get('ADMIN_EMAIL_ADDRESS') if (email_from_address in nulladdr or admin_email_address in nulladdr): return #text = 'Dear '+ username + ':\n' + ' Your account in docklet has been activated' text = '<html><h4>Dear ' + 'admin' + ':</h4>' text += '''<p> An activating request for %s in <a href='%s'>%s</a> has been sent</p> <p> Please check it !</p> <br/><br/> <p> Docklet Team, SEI, PKU</p> ''' % (username, env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL")) text += '<p>' + str(datetime.utcnow()) + '</p>' text += '</html>' subject = 'An activating request in Docklet has been sent' if admin_email_address[0] == '"': admins_addr = admin_email_address[1:-1].split(" ") else: admins_addr = admin_email_address.split(" ") alladdr = "" for addr in admins_addr: alladdr = alladdr + addr + ", " alladdr = alladdr[:-2] msg = MIMEMultipart() textmsg = MIMEText(text, 'html', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = alladdr msg.attach(textmsg) s = smtplib.SMTP() s.connect() try: s.sendmail(email_from_address, admins_addr, msg.as_string()) except Exception as e: logger.error(e) s.close()
def send_remind_activating_email(username): #admin_email_address = env.getenv('ADMIN_EMAIL_ADDRESS') nulladdr = ['\'\'', '\"\"', ''] email_from_address = settings.get('EMAIL_FROM_ADDRESS') admin_email_address = settings.get('ADMIN_EMAIL_ADDRESS') if (email_from_address in nulladdr or admin_email_address in nulladdr): return #text = 'Dear '+ username + ':\n' + ' Your account in docklet has been activated' text = '<html><h4>Dear '+ 'admin' + ':</h4>' text += '''<p> An activating request for %s in <a href='%s'>%s</a> has been sent</p> <p> Please check it !</p> <br/><br/> <p> Docklet Team, SEI, PKU</p> ''' % (username, env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL")) text += '<p>'+ str(datetime.utcnow()) + '</p>' text += '</html>' subject = 'An activating request in Docklet has been sent' if admin_email_address[0] == '"': admins_addr = admin_email_address[1:-1].split(" ") else: admins_addr = admin_email_address.split(" ") alladdr="" for addr in admins_addr: alladdr = alladdr+addr+", " alladdr=alladdr[:-2] msg = MIMEMultipart() textmsg = MIMEText(text,'html','utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = alladdr msg.attach(textmsg) s = smtplib.SMTP() s.connect() try: s.sendmail(email_from_address, admins_addr, msg.as_string()) except Exception as e: logger.error(e) s.close()
def _send_email(self, to_address, username, vcluster, days, is_released=True): email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return text = '<html><h4>Dear ' + username + ':</h4>' st_str = vcluster.stop_time.strftime("%Y-%m-%d %H:%M:%S") text += '''<p> Your workspace/vcluster(name:%s id:%d) in <a href='%s'>%s</a> has been stopped more than %d days now(stopped at:%s). </p> ''' % (vcluster.clustername, vcluster.clusterid, env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL"), days, st_str) if is_released: text += '''<p> Therefore, the workspace/vcluster has been released now.</p> <p> <b>And the data in it couldn't be recoverd</b> unless you save it.</p> <p> You can create new workspace/vcluster if you need.</p> ''' else: #day_d = self.release_days - (datetime.datetime.now() - vcluster.stop_time).days release_date = vcluster.stop_time + datetime.timedelta( days=self.release_days) day_d = (release_date - datetime.datetime.now()).days rd_str = release_date.strftime("%Y-%m-%d %H:%M:%S") text += '''<p> It will be released after <b>%s(in about %d days)</b>.</p> <p> <b>And the data in it couldn't be recoverd after releasing.</b></p> <p> Please start or save it before <b>%s(in about %d days)</b> if you want to keep the data.</p> ''' % (rd_str, day_d, rd_str, day_d) text += '''<br> <p> Note: DO NOT reply to this email!</p> <br><br> <p> <a href='http://docklet.unias.org'>Docklet Team</a>, SEI, PKU</p> ''' subject = 'Docklet workspace/vcluster releasing alert' msg = MIMEMultipart() textmsg = MIMEText(text, 'html', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg['To'] = to_address msg.attach(textmsg) s = smtplib.SMTP() s.connect() try: s.sendmail(email_from_address, to_address, msg.as_string()) except Exception as err: logger.error(traceback.format_exc()) s.close()
def mail_notification(self, notify_id): email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return {'success': 'true'} notify = Notification.query.filter_by(id=notify_id).first() notify_groups = NotificationGroups.query.filter_by( notification_id=notify_id).all() to_addr = [] groups = [] for group in notify_groups: groups.append(group.group_name) if 'all' in groups: users = User.query.all() for user in users: to_addr.append(user.e_mail) else: for group in notify_groups: users = User.query.filter_by(user_group=group.group_name).all() for user in users: to_addr.append(user.e_mail) content = notify.content text = '<html><h4>Dear ' + 'user' + ':</h4>' #user.username + ':</h4>' text += '''<p> Your account in <a href='%s'>%s</a> has been recieved a notification:</p> <p>%s</p> <br> <p> Note: DO NOT reply to this email!</p> <br><br> <p> <a href='http://docklet.unias.org'>Docklet Team</a>, SEI, PKU</p> ''' % (env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL"), content) text += '<p>' + str(datetime.utcnow()) + '</p>' text += '</html>' subject = 'Docklet Notification: ' + notify.title msg = MIMEMultipart() textmsg = MIMEText(text, 'html', 'utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg.attach(textmsg) s = smtplib.SMTP() s.connect() for address in to_addr: try: msg['To'] = address s.sendmail(email_from_address, address, msg.as_string()) except Exception as e: logger.error(e) s.close() return {"success": 'true'}
def mail_notification(self, notify_id): email_from_address = settings.get('EMAIL_FROM_ADDRESS') if (email_from_address in ['\'\'', '\"\"', '']): return {'success' : 'true'} notify = Notification.query.filter_by(id=notify_id).first() notify_groups = NotificationGroups.query.filter_by(notification_id=notify_id).all() to_addr = [] groups = [] for group in notify_groups: groups.append(group.group_name) if 'all' in groups: users = User.query.all() for user in users: to_addr.append(user.e_mail) else: for group in notify_groups: users = User.query.filter_by(user_group=group.group_name).all() for user in users: to_addr.append(user.e_mail) content = notify.content text = '<html><h4>Dear '+ 'user' + ':</h4>' #user.username + ':</h4>' text += '''<p> Your account in <a href='%s'>%s</a> has been recieved a notification:</p> <p>%s</p> <br> <p> Note: DO NOT reply to this email!</p> <br><br> <p> <a href='http://docklet.unias.org'>Docklet Team</a>, SEI, PKU</p> ''' % (env.getenv("PORTAL_URL"), env.getenv("PORTAL_URL"), content) text += '<p>'+ str(datetime.utcnow()) + '</p>' text += '</html>' subject = 'Docklet Notification: ' + notify.title msg = MIMEMultipart() textmsg = MIMEText(text,'html','utf-8') msg['Subject'] = Header(subject, 'utf-8') msg['From'] = email_from_address msg.attach(textmsg) s = smtplib.SMTP() s.connect() for address in to_addr: try: msg['To'] = address s.sendmail(email_from_address, address, msg.as_string()) except Exception as e: logger.error(e) s.close() return {"success": 'true'}