Skip to content

Commit

Permalink
feat: add bcc capability
Browse files Browse the repository at this point in the history
  • Loading branch information
johanseto committed Aug 18, 2023
1 parent a4f21df commit d19f326
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,17 @@ def add_arguments(self, parser):
required=False,
help='Indicate specific payment notification to sent id'
)
parser.add_argument(
'--bcc',
nargs="+",
required=False,
help='Indicate secret bcc to send emails'
)
def handle(self, *args, **kwargs): # lint-amnesty, pylint: disable=too-many-statements
logger.info('----Processing payment notifications to send email-----')
start_time = datetime.now()
payment_notifications_ids = kwargs.get('payment_notifications_ids')
bcc = kwargs.get('bcc')
if payment_notifications_ids:
delivery_qs = PaymentNotification.objects.filter( # pylint: disable=no-member
id__in=payment_notifications_ids,
Expand All @@ -98,7 +105,7 @@ def handle(self, *args, **kwargs): # lint-amnesty, pylint: disable=too-many-sta
for payment_notification in delivery_qs:
try:
email_multialternative_data = generate_email_multialternative_data(payment_notification)
send_email_multialternative(**email_multialternative_data, connection=mail_connection)
send_email_multialternative(**email_multialternative_data, connection=mail_connection, bcc=bcc)
correct_payment_notifications.append(payment_notification.id)
except Exception as e:
logger.error("There was an error processing payment notification %s",payment_notification.id)
Expand Down
3 changes: 2 additions & 1 deletion eox_nelp/notifications/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ def send_email_multialternative(
recipient_emails=None,
from_email=None,
connection=None,
bcc=None,
):
"""
Function to send emails with plaintext msg and html msg.
Returns:
(int): Number of emails sent.
"""
logger.info("------Sending email with subject: %s -------", subject)
msg = EmailMultiAlternatives(subject, plaintext_msg, from_email, recipient_emails, connection=connection)
msg = EmailMultiAlternatives(subject, plaintext_msg, from_email, recipient_emails, connection=connection, bcc=bcc)
msg.attach_alternative(html_msg, "text/html")
return msg.send()

Expand Down

0 comments on commit d19f326

Please sign in to comment.