Skip to content

Commit

Permalink
feat: add mail report
Browse files Browse the repository at this point in the history
Signed-off-by: r3drun3 <[email protected]>
  • Loading branch information
R3DRUN3 committed Jan 10, 2024
1 parent a171cb1 commit fbab9b5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}

39 changes: 39 additions & 0 deletions send_mail_report.py
Original file line number Diff line number Diff line change
@@ -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!')

0 comments on commit fbab9b5

Please sign in to comment.