mirror of
https://github.com/GSA/notifications-api.git
synced 2026-01-31 15:15:38 -05:00
Send emails with a friendly from name
It’s nicer to have emails with a sender name, as well as the raw email address. Amazon SES can acheive this by using the format ``` "Sender name" <sender.name@domain.com> ``` — http://docs.aws.amazon.com/ses/latest/DeveloperGuide/email-format.html We also have to remove all non-ASCII characters from the sender name, because SMTP only supports 7-bit ASCII: > A field name MUST be composed of printable US-ASCII characters (i.e., > characters that have values between 33 and 126, inclusive), except > colon. — http://www.ietf.org/rfc/rfc5322.txt We use the service name as the sender name when: - sending emails from the API - sending emails from a CSV file We use GOV.UK Notify as the sender name when: - sending invitation emails - sending password reset emails
This commit is contained in:
@@ -173,7 +173,11 @@ def process_job(job_id):
|
||||
send_email.apply_async((
|
||||
str(job.service_id),
|
||||
str(create_uuid()),
|
||||
"{}@{}".format(job.service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
'"{}" <{}@{}>'.format(
|
||||
service.name,
|
||||
service.email_from,
|
||||
current_app.config['NOTIFY_EMAIL_DOMAIN']
|
||||
).encode('ascii', 'ignore').decode('ascii'),
|
||||
encrypted,
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)),
|
||||
queue='bulk-email')
|
||||
@@ -384,8 +388,10 @@ def email_invited_user(encrypted_invitation):
|
||||
url,
|
||||
invitation['expiry_date'])
|
||||
try:
|
||||
email_from = "{}@{}".format(current_app.config['INVITATION_EMAIL_FROM'],
|
||||
current_app.config['NOTIFY_EMAIL_DOMAIN'])
|
||||
email_from = '"GOV.UK Notify" <{}@{}>'.format(
|
||||
current_app.config['INVITATION_EMAIL_FROM'],
|
||||
current_app.config['NOTIFY_EMAIL_DOMAIN']
|
||||
)
|
||||
subject_line = invitation_subject_line(invitation['user_name'], invitation['service_name'])
|
||||
aws_ses_client.send_email(email_from,
|
||||
invitation['to'],
|
||||
@@ -411,7 +417,10 @@ def password_reset_message(name, url):
|
||||
def email_reset_password(encrypted_reset_password_message):
|
||||
reset_password_message = encryption.decrypt(encrypted_reset_password_message)
|
||||
try:
|
||||
aws_ses_client.send_email(current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
|
||||
email_from = '"GOV.UK Notify" <{}>'.format(
|
||||
current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS']
|
||||
)
|
||||
aws_ses_client.send_email(email_from,
|
||||
reset_password_message['to'],
|
||||
"Reset your GOV.UK Notify password",
|
||||
password_reset_message(name=reset_password_message['name'],
|
||||
@@ -433,7 +442,10 @@ def registration_verification_template(name, url):
|
||||
def email_registration_verification(encrypted_verification_message):
|
||||
verification_message = encryption.decrypt(encrypted_verification_message)
|
||||
try:
|
||||
aws_ses_client.send_email(current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS'],
|
||||
email_from = '"GOV.UK Notify" <{}>'.format(
|
||||
current_app.config['VERIFY_CODE_FROM_EMAIL_ADDRESS']
|
||||
)
|
||||
aws_ses_client.send_email(email_from,
|
||||
verification_message['to'],
|
||||
"Confirm GOV.UK Notify registration",
|
||||
registration_verification_template(name=verification_message['name'],
|
||||
|
||||
@@ -359,7 +359,7 @@ def send_notification(notification_type):
|
||||
send_email.apply_async((
|
||||
service_id,
|
||||
notification_id,
|
||||
"{}@{}".format(service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
'"{}" <{}@{}>'.format(service.name, service.email_from, current_app.config['NOTIFY_EMAIL_DOMAIN']),
|
||||
encryption.encrypt(notification),
|
||||
datetime.utcnow().strftime(DATETIME_FORMAT)
|
||||
), queue='email')
|
||||
|
||||
Reference in New Issue
Block a user