예제 #1
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your beans in <a href='%s'>docklet</a> are %d now. </p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If your beans are less than or equal to 0, all your worksapces will be stopped.</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please apply for more beans to keep your workspaces running by following link:</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='%s/beans/application/'>%s/beans/application/</p>
               <br>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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()
예제 #2
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your beans in <a href='%s'>docklet</a> are %d now. </p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If your beans are less than or equal to 0, all your worksapces will be stopped.</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please apply for more beans to keep your workspaces running by following link:</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='%s/beans/application/'>%s/beans/application/</p>
               <br>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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()
예제 #3
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your account in <a href='%s'>%s</a> has been activated</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enjoy your personal workspace in the cloud !</p>
               <br>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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()
예제 #4
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your account in <a href='%s'>%s</a> has been activated</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Enjoy your personal workspace in the cloud !</p>
               <br>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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()
예제 #5
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A bug has been report by %s.</p>
               <br/>
               <strong>&nbsp; %s &nbsp;</strong>
               <br/>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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'}
예제 #6
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A bug has been report by %s.</p>
               <br/>
               <strong>&nbsp; %s &nbsp;</strong>
               <br/>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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'}
예제 #7
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;An activating request for %s in <a href='%s'>%s</a> has been sent</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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()
예제 #8
0
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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;An activating request for %s in <a href='%s'>%s</a> has been sent</p>
               <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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()
예제 #9
0
 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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Therefore, the workspace/vcluster has been released now.</p>
                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>And the data in it couldn't be recoverd</b> unless you save it.</p>
                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;It will be released after <b>%s(in about %d days)</b>.</p>
                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>And the data in it couldn't be recoverd after releasing.</b></p>
                    <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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()
예제 #10
0
    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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your account in <a href='%s'>%s</a> has been recieved a notification:</p>
                   <p>%s</p>
                   <br>
                   <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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'}
예제 #11
0
    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>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Your account in <a href='%s'>%s</a> has been recieved a notification:</p>
                   <p>%s</p>
                   <br>
                   <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;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'}