Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added BCC functionality for email sending #510

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion config.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ smtp:
user: SMTP_AUTH_USER

admin:
# This address will get an email, when a new software was added through the frontend
# This address will get an email, for any error or new project added etc.
email: [email protected]
# This email will always get a copy of every email sent, even for user-only mails like the "Your report is ready" mail. Put an empty string if you do not want that: ""
bcc_email: ""
# no_emails: True will suppress all emails. Helpful in development servers
no_emails: True

Expand Down
11 changes: 7 additions & 4 deletions lib/email_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def send_email(message, receiver_email):
server.login(config['smtp']['user'], config['smtp']['password'])
server.sendmail(config['smtp']['sender'], receiver_email, message.encode('utf-8'))


def send_admin_email(subject, body):
message = """\
From: {smtp_sender}
Expand All @@ -31,13 +30,14 @@ def send_admin_email(subject, body):
url=config['cluster']['metrics_url'],
receiver_email=config['admin']['email'],
smtp_sender=config['smtp']['sender'])
send_email(message, config['admin']['email'])
send_email(message, [config['admin']['email'], config['admin']['bcc_email']])


def send_error_email(receiver_email, error, run_id=None, name=None, machine=None):
message = """\
From: {smtp_sender}
To: {receiver_email}
Bcc: {bcc_email}
Subject: Your Green Metrics analysis has encountered problems

Unfortunately, your Green Metrics analysis has run into some issues and could not be completed.
Expand All @@ -58,16 +58,18 @@ def send_error_email(receiver_email, error, run_id=None, name=None, machine=None
errors=error,
name=name,
machine=machine,
bcc_mail=config['admin']['bcc_email'],
url=config['cluster']['metrics_url'],
run_id=run_id,
smtp_sender=config['smtp']['sender'])
send_email(message, receiver_email)
send_email(message, [receiver_email, config['admin']['bcc_email']])


def send_report_email(receiver_email, report_id, name, machine=None):
message = """\
From: {smtp_sender}
To: {receiver_email}
Bcc: {bcc_mail}
Subject: Your Green Metric report is ready

Run Name: {name}
Expand All @@ -84,9 +86,10 @@ def send_report_email(receiver_email, report_id, name, machine=None):
report_id=report_id,
machine=machine,
name=name,
bcc_mail=config['admin']['bcc_email'],
url=config['cluster']['metrics_url'],
smtp_sender=config['smtp']['sender'])
send_email(message, receiver_email)
send_email(message, [receiver_email, config['admin']['bcc_email']])


if __name__ == '__main__':
Expand Down