@@ -100,7 +100,23 @@ def _create_email(self, email: dict, email_id: str) -> Mail:
100100 mail .add_content (Content ('text/html' , email .get ('body' , '(no content)' )))
101101 self .log_debug ('added content to email %s' , email_id )
102102
103- mail .from_email = Email (email .get ('from' ))
103+ # at some point SendGrid had the ability to send from subdomains of a verified
104+ # domain, so verifying {domain} let us send from {client}.{domain}
105+ # ...this feature went away so the following is a work-around which
106+ # changes the from address to the verified root domain but using reply-to
107+ # so that the email still gets routed back to the original client
108+ # ...this is a pretty ugly hack and the real fix is to change the logic of
109+ # how we sign up users on clients to use the new format {user}-{client}@{domain}
110+ from_email = email ['from' ]
111+ user , client_domain = from_email .split ('@' )
112+ client_domain_parts = client_domain .split ('.' )
113+ if len (client_domain_parts ) == 3 :
114+ client = client_domain_parts [0 ]
115+ domain = '.' .join (client_domain_parts [1 :])
116+ mail .from_email = Email ('{}-{}@{}' .format (user , client , domain ))
117+ mail .reply_to = Email (from_email )
118+ else :
119+ mail .from_email = Email (from_email )
104120 self .log_debug ('added from to email %s' , email_id )
105121
106122 for i , attachment in enumerate (email .get ('attachments' , [])):
0 commit comments