Skip to content

Commit e4618ce

Browse files
authored
Allow for comma-separated list of recipients
1 parent 678bd1e commit e4618ce

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

Diff for: .github/scripts/send_report.py

+34-5
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,44 @@ def create_email_body(repo_name, stats):
3636
"""
3737
return body
3838

39-
def send_email(recipient_email, subject, body):
40-
"""Send email using SendGrid"""
39+
# def send_email(recipient_email, subject, body):
40+
# """Send email using SendGrid"""
41+
# sg = SendGridAPIClient(os.environ['SENDGRID_API_KEY'])
42+
43+
# from_email = Email(os.environ['SENDER_EMAIL'])
44+
# to_email = To(recipient_email)
45+
# content = Content("text/plain", body)
46+
47+
# mail = Mail(from_email, to_email, subject, content)
48+
49+
# try:
50+
# response = sg.client.mail.send.post(request_body=mail.get())
51+
# print(f"Email sent successfully. Status code: {response.status_code}")
52+
# except Exception as e:
53+
# print(f"Error sending email: {e}")
54+
55+
def send_email(recipient_emails, subject, body):
56+
"""Send email using SendGrid to multiple recipients"""
4157
sg = SendGridAPIClient(os.environ['SENDGRID_API_KEY'])
4258

4359
from_email = Email(os.environ['SENDER_EMAIL'])
44-
to_email = To(recipient_email)
45-
content = Content("text/plain", body)
4660

47-
mail = Mail(from_email, to_email, subject, content)
61+
# Convert string to list if a single string is provided
62+
if isinstance(recipient_emails, str):
63+
recipient_emails = [recipient_emails]
64+
65+
# Create personalization object with multiple recipients
66+
mail = Mail(
67+
from_email=from_email,
68+
subject=subject,
69+
)
70+
71+
personalization = Personalization()
72+
for email in recipient_emails:
73+
personalization.add_to(To(email))
74+
75+
mail.add_personalization(personalization)
76+
mail.add_content(Content("text/plain", body))
4877

4978
try:
5079
response = sg.client.mail.send.post(request_body=mail.get())

0 commit comments

Comments
 (0)