Skip to content

Commit

Permalink
feat: add ACE_CHANNEL_BRAZE_FROM_EMAIL setting (#98)
Browse files Browse the repository at this point in the history
This setting will override a message's normal from address.
Braze has specific constraints, where it only allows sending emails
from whitelisted from addresses.
  • Loading branch information
mikix authored Mar 26, 2021
1 parent 1fca03c commit 77d3a4c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Change Log
Unreleased
~~~~~~~~~~

[1.1.0] - 2021-03-26
~~~~~~~~~~~~~~~~~~~~

* Braze: Add ACE_CHANNEL_BRAZE_FROM_EMAIL setting to override the normal from address
* Sailthru: Remove Braze rollout waffle flag

[1.0.1] - 2021-03-15
Expand Down
2 changes: 1 addition & 1 deletion edx_ace/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .recipient import Recipient
from .recipient_resolver import RecipientResolver

__version__ = '1.0.1'
__version__ = '1.1.0'

default_app_config = 'edx_ace.apps.EdxAceConfig'

Expand Down
9 changes: 8 additions & 1 deletion edx_ace/channel/braze.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BrazeEmailChannel(EmailChannelMixin, Channel):
.. settings_start
ACE_CHANNEL_BRAZE_API_KEY = "1c304d0d-c800-4da3-bfaa-41b1189b34cb"
ACE_CHANNEL_BRAZE_APP_ID = "f6232495-6ad6-4310-bab5-5673768856aa"
ACE_CHANNEL_BRAZE_FROM_EMAIL = "Open edX <openedx@example.com>"
ACE_CHANNEL_BRAZE_REST_ENDPOINT = "rest.iad-01.braze.com"
ACE_CHANNEL_BRAZE_CAMPAIGNS = {
"deletionnotificationmessage": "campaign_id:variation_id"
Expand All @@ -60,6 +61,7 @@ class BrazeEmailChannel(EmailChannelMixin, Channel):
_APP_ID_SETTING = 'ACE_CHANNEL_BRAZE_APP_ID'
_CAMPAIGNS_SETTING = 'ACE_CHANNEL_BRAZE_CAMPAIGNS' # optional
_ENDPOINT_SETTING = 'ACE_CHANNEL_BRAZE_REST_ENDPOINT'
_FROM_EMAIL_SETTING = 'ACE_CHANNEL_BRAZE_FROM_EMAIL' # optional

@classmethod
def enabled(cls):
Expand Down Expand Up @@ -106,6 +108,11 @@ def deliver(self, message, rendered_message):
transactional = message.options.get('transactional', False)
body_html = self.make_simple_html_template(rendered_message.head_html, rendered_message.body_html)

# Allow our settings to override the from address, because Braze requires specific configured from addresses,
# which are tied to specific ip addresses that are "ip warmed" to help delivery of the emails not get sent
# to promotional/spam inboxes.
from_address = getattr(settings, self._FROM_EMAIL_SETTING, None) or self.get_from_address(message)

logger = message.get_message_specific_logger(LOG)
logger.debug('Sending to Braze')

Expand All @@ -122,7 +129,7 @@ def deliver(self, message, rendered_message):
'email': {
'app_id': getattr(settings, self._APP_ID_SETTING),
'subject': self.get_subject(rendered_message),
'from': self.get_from_address(message),
'from': from_address,
'reply_to': message.options.get('reply_to'),
'body': body_html,
'plaintext_body': rendered_message.body,
Expand Down
10 changes: 8 additions & 2 deletions edx_ace/tests/channel/test_braze.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ def test_transactional(self):
mock_post = self.deliver_email(options={'transactional': True})
assert mock_post.call_args[1]['json']['recipient_subscription_state'] == 'all'

def test_from_address(self):
"""Can set a from address in options"""
def test_from_address_in_message(self):
"""Can set a from address in message options"""
mock_post = self.deliver_email(options={'from_address': 'testing@example.com'})
assert mock_post.call_args[1]['json']['messages']['email']['from'] == 'testing@example.com'

@override_settings(ACE_CHANNEL_BRAZE_FROM_EMAIL='settings@example.com')
def test_from_address_in_settings(self):
"""Can set a from address in settings, which will be preferred over the message options"""
mock_post = self.deliver_email(options={'from_address': 'message@example.com'})
assert mock_post.call_args[1]['json']['messages']['email']['from'] == 'settings@example.com'

def test_reply_to(self):
"""Can set a reply-to address in options"""
mock_post = self.deliver_email(options={'reply_to': 'reply@example.com'})
Expand Down

0 comments on commit 77d3a4c

Please sign in to comment.