From fbab9b5e4a50501551ca5ca07a96ba9253d863ab Mon Sep 17 00:00:00 2001 From: r3drun3 Date: Wed, 10 Jan 2024 15:19:42 +0100 Subject: [PATCH] feat: add mail report Signed-off-by: r3drun3 --- .github/workflows/patch.yaml | 13 ++++++++++++ send_mail_report.py | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 send_mail_report.py diff --git a/.github/workflows/patch.yaml b/.github/workflows/patch.yaml index 8622a3c..ada2df2 100644 --- a/.github/workflows/patch.yaml +++ b/.github/workflows/patch.yaml @@ -65,6 +65,19 @@ jobs: - name: Docker Push Patched Image + id: push if: steps.login.conclusion == 'success' run: | docker push ghcr.io/r3drun3/immunize/${{ steps.copa.outputs.patched-image }} + + - name: Send Mail Report + if: steps.push.conclusion == 'success' + run: | + PATCHED_IMAGES=$(echo "${{ steps.copa.outputs.patched-image }}" | tr '\n' ',' | sed 's/,$//') + echo "PATCHED_IMAGES=${PATCHED_IMAGES}" >> $GITHUB_ENV + python send_mail_report.py + env: + EMAIL_RECIPIENTS: ${{ secrets.EMAIL_RECIPIENTS }} + EMAIL_ADDRESS: ${{ secrets.EMAIL_ADDRESS }} + EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }} + diff --git a/send_mail_report.py b/send_mail_report.py new file mode 100644 index 0000000..99241d4 --- /dev/null +++ b/send_mail_report.py @@ -0,0 +1,39 @@ +# SEND MAIL REPORT WITH PATCHED IMAGES + +import smtplib +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +import os + +# Get patched image information from GitHub Actions context +patched_images_str = os.environ.get('PATCHED_IMAGES', '') +patched_images = patched_images_str.split(',') +print("Pathed images: ", patched_images) + +# Prepare the email content +subject = 'Patched Image Report' +body = f'Patched Images:\n\n{", ".join(patched_images)}' + +# Get email and password from GitHub secrets +email_address = os.environ.get('EMAIL_ADDRESS', '') +print("Email address:", email_address) +email_password = os.environ.get('EMAIL_PASSWORD', '') + +# Get email recipients from GitHub secret +recipients = os.environ.get('EMAIL_RECIPIENTS', '').split(',') +print("Recipients:", recipients) + +# Prepare the email message +message = MIMEMultipart() +message['From'] = email_address +message['To'] = ', '.join(recipients) +message['Subject'] = subject +message.attach(MIMEText(body, 'plain')) + +# Connect to the SMTP server and send the email +with smtplib.SMTP('smtp.gmail.com', 587) as server: + server.starttls() + server.login(email_address, email_password) + server.send_message(message) + +print('Email sent successfully!')