@@ -307,34 +307,16 @@ async def reject_user_account(
307307 return pre_registration_id
308308
309309
310- async def send_approval_email_to_user (
310+ def _create_product_and_user_data (
311311 app : web .Application ,
312312 * ,
313313 product_name : ProductName ,
314- invitation_link : HttpUrl ,
315314 user_email : LowerCaseEmailStr ,
316315 first_name : str ,
317316 last_name : str ,
318- ) -> None :
319- """Send approval email to user with invitation link.
320-
321- Args:
322- app: The web application instance
323- product_name: Product name for which the user was approved
324- invitation_link: URL link for the invitation
325- user_email: Email of the user to send approval to
326- user_name: Name of the user
327- """
328- from notifications_library ._email import compose_email , create_email_session
329- from notifications_library ._email_render import (
330- get_support_address ,
331- get_user_address ,
332- render_email_parts ,
333- )
317+ ):
318+ """Create ProductData and UserData objects for email rendering."""
334319 from notifications_library ._models import ProductData , ProductUIData , UserData
335- from notifications_library ._render import (
336- create_render_environment_from_notifications_library ,
337- )
338320
339321 # Get product data from the app
340322 product = get_product (app , product_name = product_name )
@@ -381,6 +363,37 @@ async def send_approval_email_to_user(
381363 last_name = last_name ,
382364 )
383365
366+ return product_data , user_data
367+
368+
369+ async def send_approval_email_to_user (
370+ app : web .Application ,
371+ * ,
372+ product_name : ProductName ,
373+ invitation_link : HttpUrl ,
374+ user_email : LowerCaseEmailStr ,
375+ first_name : str ,
376+ last_name : str ,
377+ ) -> None :
378+ from notifications_library ._email import compose_email , create_email_session
379+ from notifications_library ._email_render import (
380+ get_support_address ,
381+ get_user_address ,
382+ render_email_parts ,
383+ )
384+ from notifications_library ._render import (
385+ create_render_environment_from_notifications_library ,
386+ )
387+
388+ # Create product and user data
389+ product_data , user_data = _create_product_and_user_data (
390+ app ,
391+ product_name = product_name ,
392+ user_email = user_email ,
393+ first_name = first_name ,
394+ last_name = last_name ,
395+ )
396+
384397 # Prepare event data
385398 event_extra_data = {
386399 "host" : str (invitation_link ).split ("?" )[0 ],
@@ -408,3 +421,59 @@ async def send_approval_email_to_user(
408421 # Send email
409422 async with create_email_session (settings = SMTPSettings .create_from_envs ()) as smtp :
410423 await smtp .send_message (msg )
424+
425+
426+ async def send_rejection_email_to_user (
427+ app : web .Application ,
428+ * ,
429+ product_name : ProductName ,
430+ user_email : LowerCaseEmailStr ,
431+ first_name : str ,
432+ last_name : str ,
433+ host : str ,
434+ ) -> None :
435+ from notifications_library ._email import compose_email , create_email_session
436+ from notifications_library ._email_render import (
437+ get_support_address ,
438+ get_user_address ,
439+ render_email_parts ,
440+ )
441+ from notifications_library ._render import (
442+ create_render_environment_from_notifications_library ,
443+ )
444+
445+ # Create product and user data
446+ product_data , user_data = _create_product_and_user_data (
447+ app ,
448+ product_name = product_name ,
449+ user_email = user_email ,
450+ first_name = first_name ,
451+ last_name = last_name ,
452+ )
453+
454+ # Prepare event data (based on test_email_events.py)
455+ event_extra_data = {
456+ "host" : host ,
457+ }
458+
459+ # Render email parts
460+ parts = render_email_parts (
461+ env = create_render_environment_from_notifications_library (),
462+ event_name = "on_account_rejected" ,
463+ user = user_data ,
464+ product = product_data ,
465+ ** event_extra_data ,
466+ )
467+
468+ # Compose email
469+ msg = compose_email (
470+ from_ = get_support_address (product_data ),
471+ to = get_user_address (user_data ),
472+ subject = parts .subject ,
473+ content_text = parts .text_content ,
474+ content_html = parts .html_content ,
475+ )
476+
477+ # Send email
478+ async with create_email_session (settings = SMTPSettings .create_from_envs ()) as smtp :
479+ await smtp .send_message (msg )
0 commit comments