mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 15:46:07 -05:00
ensure emails are formatted before sending
we allow some invalid to addresses - for example, phone numbers with spaces or brackets - in the database. This is so that users can match up their data in a format that they expect (since they passed it in). When we send SMS, we strip this formatting just before sending - but we weren't with email. This commit changes that and adds some tests. It also adds formatting for reply_to addresses. We should never expect invalid reply_to email addresses in our data, but just in case, lets validate them here. Also, bump requirements.txt to capture some more email validation
This commit is contained in:
@@ -3,7 +3,8 @@ from datetime import datetime
|
||||
|
||||
from flask import current_app
|
||||
from notifications_utils.recipients import (
|
||||
validate_and_format_phone_number
|
||||
validate_and_format_phone_number,
|
||||
validate_and_format_email_address
|
||||
)
|
||||
from notifications_utils.template import HTMLEmailTemplate, PlainTextEmailTemplate, SMSMessageTemplate
|
||||
|
||||
@@ -130,11 +131,11 @@ def send_email_to_provider(notification):
|
||||
|
||||
reference = provider.send_email(
|
||||
from_address,
|
||||
notification.to,
|
||||
validate_and_format_email_address(notification.to),
|
||||
plain_text_email.subject,
|
||||
body=str(plain_text_email),
|
||||
html_body=str(html_email),
|
||||
reply_to_address=email_reply_to,
|
||||
reply_to_address=validate_and_format_email_address(email_reply_to) if email_reply_to else None,
|
||||
)
|
||||
notification.reference = reference
|
||||
update_notification(notification, provider)
|
||||
|
||||
Reference in New Issue
Block a user