-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_mail_report.py
49 lines (40 loc) · 1.8 KB
/
send_mail_report.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import yaml
import smtplib
from datetime import datetime
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
# Get the path to the Github Action YAML file
yaml_file_path = os.path.join(os.path.dirname(__file__), '.github/workflows/patch.yaml')
# Read the YAML file to get the patched image list
with open(yaml_file_path, 'r') as yaml_file:
yaml_content = yaml.load(yaml_file, Loader=yaml.FullLoader)
patched_images = yaml_content.get('jobs', {}).get('immunize', {}).get('strategy', {}).get('matrix', {}).get('images', [])
print("Patched images:", patched_images)
current_timestamp = datetime.now().strftime('%Y-%m-%d')
# Prepare the HTML content
subject = 'IMMUNIZE: OCI Images Patching Report'
html_body = '<h1>Patched Images 💉 {}</h1><ul>'.format(current_timestamp)
for image in patched_images:
html_body += f'<li>{image}</li>'
html_body += '</ul><br />'
html_body += 'check the full catalog 📚 <a href="https://github.com/R3DRUN3?tab=packages&repo_name=immunize">here</a> !'
html_body += '<br /><br />'
html_body += '<h2>Stay Safe! 💪</h2>'
# Get email and password from GitHub secrets
email_address = os.environ.get('EMAIL_ADDRESS', '')
email_password = os.environ.get('EMAIL_PASSWORD', '')
# Get email recipients from GitHub secret
recipients = os.environ.get('EMAIL_RECIPIENTS', '').split(',')
# Prepare the email message
message = MIMEMultipart()
message['From'] = email_address
message['To'] = ', '.join(recipients)
message['Subject'] = subject
message.attach(MIMEText(html_body, 'html'))
# Connect to the GMAIL SMTP server and send the emails
with smtplib.SMTP('smtp.gmail.com', 587) as server:
server.starttls()
server.login(email_address, email_password)
server.sendmail(email_address, recipients, message.as_string())
print('Emails sent successfully!')