mem_daemon_mail.py
def sendMail(receiver, sender, password, text, smtp, port, threshold, col_log,
             selfie):
    """
    Function to send out email based on output of mem_daemon

    Args:
        receiver (str): comma-separated receiver email address(es)
        sender (str): sender email adress
        password (str): plaintext password for sender (unsafe)
        text (str): proc string to display for process termination
        smtp (str): smtp domain of sender
        port (int): smtp port
        threshold (int): RAM threshold exceeded
        col_log (int): number of columns in proc-message
        selfie (int): 1 if own user, 0 if foreign user
    """
    # define mail variables
    subject_1 = "[Process Termination Notification] "
    subject_0 = "[RAM Threshold Notification] "
    pre_text_1 = ('Dear User,\n\n`{}` was terminated on {} as the total used '
                  'RAM threshold of {}% was exceeded.\n\nBelow is a footprint '
                  'of the process before it was terminated:\n\n')
    pre_text_0 = ('Dear User,\n\nThe total used RAM threshold of {}% '
                  'was exceeded by a process from another user `{}`'
                  ' on {}.\n\nBelow is a footprint of the process,'
                  ' for your information:\n\n')
    end = "\n\nYour Memory Daemon"
    # get command information from (assumed) last column
    command = text.split()[(col_log * 2) - 1]
    user = text.split()[(col_log + 2) - 1]
    if selfie == 1:
        subject = subject_1 + command
        pre_text = pre_text_1.format(command, getCurrentTime(), threshold)
    elif selfie == 0:
        subject = subject_0 + command
        pre_text = pre_text_0.format(threshold, user, getCurrentTime())
    text = (pre_text + "```\n" + re.sub(
        "<space>", "\n", re.sub(r"\s+", " ", re.sub(r"\n", "<space>", text))) +
            "\n```" + end)
    msg = MIMEText(text)
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = receiver
    msg["Date"] = formatdate(localtime=True)
    # connect to SMTP server
    s = smtplib.SMTP(smtp, port)
    # start TLS secure connection
    s.starttls()
    # log into SMTP server
    s.login(sender, password)
    # send email(s) and quit
    receiver = re.split(r"\s*,\s*", receiver)
    for rec in receiver:
        s.sendmail(sender, rec, msg.as_string())
    s.quit()

    Function to send out email based on output of mem_daemon

    Args:
        receiver (str): comma-separated receiver email address(es)
        sender (str): sender email adress
        password (str): plaintext password for sender (unsafe)
        text (str): proc string to display for process termination
        smtp (str): smtp domain of sender
        port (int): smtp port
        threshold (int): RAM threshold exceeded
        col_log (int): number of columns in proc-message
        selfie (int): 1 if own user, 0 if foreign user
    
Function to send out email based on output of mem_daemon
Function to send out email based on output of mem_daemon
def sendMail(receiver, sender, password, text, smtp, port, threshold, col_log,
             selfie):
    subject_1 = "[Process Termination Notification] "
    subject_0 = "[RAM Threshold Notification] "
    pre_text_1 = ('Dear User,\n\n`{}` was terminated on {} as the total used '
                  'RAM threshold of {}% was exceeded.\n\nBelow is a footprint '
                  'of the process before it was terminated:\n\n')
    pre_text_0 = ('Dear User,\n\nThe total used RAM threshold of {}% '
                  'was exceeded by a process from another user `{}`'
                  ' on {}.\n\nBelow is a footprint of the process,'
                  ' for your information:\n\n')
    end = "\n\nYour Memory Daemon"
    command = text.split()[(col_log * 2) - 1]
    user = text.split()[(col_log + 2) - 1]
    if selfie == 1:
        subject = subject_1 + command
        pre_text = pre_text_1.format(command, getCurrentTime(), threshold)
    elif selfie == 0:
        subject = subject_0 + command
        pre_text = pre_text_0.format(threshold, user, getCurrentTime())
    text = (pre_text + "```\n" + re.sub(
        "<space>", "\n", re.sub(r"\s+", " ", re.sub(r"\n", "<space>", text))) +
            "\n```" + end)
    msg = MIMEText(text)
    msg['Subject'] = subject
    msg['From'] = sender
    msg['To'] = receiver
    msg["Date"] = formatdate(localtime=True)
    s = smtplib.SMTP(smtp, port)
    s.starttls()
    s.login(sender, password)
    receiver = re.split(r"\s*,\s*", receiver)
    for rec in receiver:
        s.sendmail(sender, rec, msg.as_string())
    s.quit()
def sendMail ( receiver , sender , password , text , smtp , port , threshold , col_log , selfie ) : subject_1 = "[Process Termination Notification] " subject_0 = "[RAM Threshold Notification] " pre_text_1 = ( 'Dear User,\n\n`{}` was terminated on {} as the total used ' 'RAM threshold of {}% was exceeded.\n\nBelow is a footprint ' 'of the process before it was terminated:\n\n' ) pre_text_0 = ( 'Dear User,\n\nThe total used RAM threshold of {}% ' 'was exceeded by a process from another user `{}`' ' on {}.\n\nBelow is a footprint of the process,' ' for your information:\n\n' ) end = "\n\nYour Memory Daemon" command = text . split ( ) [ ( col_log * 2 ) - 1 ] user = text . split ( ) [ ( col_log + 2 ) - 1 ] if selfie == 1 : subject = subject_1 + command pre_text = pre_text_1 . format ( command , getCurrentTime ( ) , threshold ) elif selfie == 0 : subject = subject_0 + command pre_text = pre_text_0 . format ( threshold , user , getCurrentTime ( ) ) text = ( pre_text + "```\n" + re . sub ( "<space>" , "\n" , re . sub ( r"\s+" , " " , re . sub ( r"\n" , "<space>" , text ) ) ) + "\n```" + end ) msg = MIMEText ( text ) msg [ 'Subject' ] = subject msg [ 'From' ] = sender msg [ 'To' ] = receiver msg [ "Date" ] = formatdate ( localtime = True ) s = smtplib . SMTP ( smtp , port ) s . starttls ( ) s . login ( sender , password ) receiver = re . split ( r"\s*,\s*" , receiver ) for rec in receiver : s . sendmail ( sender , rec , msg . as_string ( ) ) s . quit ( )
Function to send out email based on output of mem_daemon
Function to send out email based on output of mem_daemon
"""
    Function to send out email based on output of mem_daemon

    Args:
        receiver (str): comma-separated receiver email address(es)
        sender (str): sender email adress
        password (str): plaintext password for sender (unsafe)
        text (str): proc string to display for process termination
        smtp (str): smtp domain of sender
        port (int): smtp port
        threshold (int): RAM threshold exceeded
        col_log (int): number of columns in proc-message
        selfie (int): 1 if own user, 0 if foreign user
    """ # define mail variables # get command information from (assumed) last column # connect to SMTP server # start TLS secure connection # log into SMTP server # send email(s) and quit
receiver
comma-separated receiver email address(es)
comma - separated receiver email address ( es )
sender
sender email adress
sender email adress
password
plaintext password for sender (unsafe)
plaintext password for sender ( unsafe )
text
proc string to display for process termination
proc string to display for process termination
smtp
smtp domain of sender
smtp domain of sender
port
None
threshold
RAM threshold exceeded
RAM threshold exceeded
col_log
number of columns in proc-message
number of columns in proc - message
selfie
1 if own user, 0 if foreign user
1 if own user 0 if foreign user