Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add email service #123

Merged
merged 21 commits into from
Mar 9, 2025
Merged

Add email service #123

merged 21 commits into from
Mar 9, 2025

Conversation

ttoino
Copy link
Member

@ttoino ttoino commented Feb 23, 2023

Closes #82.

Adds a new EmailService with a method send, which receives an instance of EmailBuilder.
Two builders were implemented: SimpleEmailBuilder, which receives all properties directly, and TemplateEmailBuilder, which generates the subject, content and attachments from the given data using mustache templates.

Each different template email should be a subclass of TemplateEmailBuilder, here's an example:

data class ExampleContext(
    val title: String,
    val todos: List<String>
)

class ExampleEmailBuilder : TemplateEmailBuilder<ExampleContext>("example")
<!-- .../resources/templates/email/example.mustache -->
---
subject: Example: {{title}}
attachments:
    - {{title}}.txt :: classpath:application.properties
inline:
    - image :: classpath:image.png
---

# {{title}}

{{#todos}}
- {{.}}
{{/todos}}

![Image](cid:image)
service.send(
    ExampleEmailBuilder()
        .data(ExampleContext("Grocery list", listOf("Potatoes", "Tomatoes", "Cheese")))
        .to("email@email.com")
)

This sends an email that looks something like this:

image image

Review checklist

  • Contains enough appropriate tests
  • Behavior is as expected
  • Clean, well structured code

@ttoino

This comment was marked as resolved.

@ttoino ttoino force-pushed the feature/email-service branch 2 times, most recently from 78a6476 to c1c29c2 Compare February 25, 2023 11:53
@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2023

Codecov Report

Patch coverage: 16.66% and project coverage change: -11.07 ⚠️

Comparison is base (2a423b6) 88.49% compared to head (33dc731) 77.43%.

Additional details and impacted files
@@              Coverage Diff               @@
##             develop     #123       +/-   ##
==============================================
- Coverage      88.49%   77.43%   -11.07%     
- Complexity       345      355       +10     
==============================================
  Files             61       67        +6     
  Lines            791      935      +144     
  Branches          65       76       +11     
==============================================
+ Hits             700      724       +24     
- Misses            57      177      +120     
  Partials          34       34               
Impacted Files Coverage Δ
.../pt/up/fe/ni/website/backend/BackendApplication.kt 50.00% <ø> (ø)
...up/fe/ni/website/backend/email/BaseEmailBuilder.kt 0.00% <0.00%> (ø)
.../fe/ni/website/backend/email/SimpleEmailBuilder.kt 0.00% <0.00%> (ø)
...e/ni/website/backend/email/TemplateEmailBuilder.kt 0.00% <0.00%> (ø)
...t/up/fe/ni/website/backend/service/EmailService.kt 37.50% <37.50%> (ø)
.../fe/ni/website/backend/config/email/EmailConfig.kt 100.00% <100.00%> (ø)
...site/backend/config/email/EmailConfigProperties.kt 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ttoino ttoino marked this pull request as ready for review March 4, 2023 01:43
@ttoino
Copy link
Member Author

ttoino commented Mar 4, 2023

I'm marking as ready for review, but a few things are still missing:

  • Support for images and other embedded resources like styles
  • Default email layout and styles - Supported, design not finalized
  • Some kind of testing (not sure what to do here)
  • Maybe markdown support
  • Documentation - in the wiki

@github-actions
Copy link

Check the documentation preview: https://64148c8507396b40a734ad10--niaefeup-backend-docs.netlify.app

@github-actions
Copy link

Check the documentation preview: https://64161557a5113f2455baeb87--niaefeup-backend-docs.netlify.app

@jamcunha jamcunha self-requested a review March 19, 2023 14:00
Copy link
Member

@BrunoRosendo BrunoRosendo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What a great PR 🎉 Tremendous job! I left minor/cosmetic suggestions

One thing I don't like is having email as a top-level package, I think we already have enough of them. What do you think of storing the builders under service/email/? together with EmailService?

this.data = data
}

override fun build(helper: MimeMessageHelper, emailConfigProperties: EmailConfigProperties) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is a bit verbose, I'd consider splitting it into more methods if possible

@github-actions
Copy link

Check the documentation preview: https://641c7e9b8ddee704dad18da7--niaefeup-backend-docs.netlify.app

@bdmendes bdmendes self-requested a review March 29, 2023 15:22
@BrunoRosendo
Copy link
Member

Have you decided something about the tests?

@ttoino ttoino force-pushed the feature/email-service branch from 744c69c to 33dc731 Compare June 28, 2023 15:58
@github-actions
Copy link

Check the documentation preview: https://649c5a2becd22626c57b25e2--niaefeup-backend-docs.netlify.app

Copy link

Check the documentation preview: https://6748a29cc73b7330bd8b3797--niaefeup-backend-docs.netlify.app

@MRita443 MRita443 requested review from MRita443 and removed request for jamcunha December 4, 2024 16:46
@MRita443 MRita443 requested a review from BrunoRosendo January 24, 2025 17:22
Copy link

Check the documentation preview: https://6793cddd62e627d5c653cc1b--niaefeup-backend-docs.netlify.app

Copy link
Collaborator

@MRita443 MRita443 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looking good so far. Shouldn't we add tests for SimpleEmailBuilder and TemplateEmailBuildertoo?

@rubuy-74
Copy link
Contributor

rubuy-74 commented Jan 26, 2025

Don't forget to add instructions for testing on the wiki.

@rubuy-74 rubuy-74 requested a review from MRita443 January 28, 2025 15:31
Copy link
Member

@BrunoRosendo BrunoRosendo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the changes from the last time I saw it. Good job with the tests!

One thing that would be great to improve is the size of the PRs. We didn't use to do this in NI but it's much easier to do small and incremental PRs, even if the feature or issue isn't fully closed. This should help make the reviews quicker and avoid having stale CRs for months at a time

PS: you need to fix the lint, it seems

Copy link
Member

@BrunoRosendo BrunoRosendo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approve to unblock, but look at the comments

Copy link
Collaborator

@MRita443 MRita443 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job with the tests! There's some simple errors as of now if you could fix that. And don't forget the lint and comments here

@rubuy-74 rubuy-74 force-pushed the feature/email-service branch from c6efe91 to 78fa260 Compare February 27, 2025 18:50
Copy link

Check the documentation preview: https://67c0b65a3bf3287b25d1df13--niaefeup-backend-docs.netlify.app

Copy link
Collaborator

@MRita443 MRita443 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! A comment for posteriority: If the email tests and application context load fails, delete the website-be-h2-db.mv.db file in your home folder

Copy link

github-actions bot commented Mar 9, 2025

Check the documentation preview: https://67cdae385ff4f4a51dcb8f90--niaefeup-backend-docs.netlify.app

@MRita443 MRita443 merged commit 976baaa into develop Mar 9, 2025
3 checks passed
@MRita443 MRita443 deleted the feature/email-service branch March 9, 2025 15:12
Copy link

github-actions bot commented Mar 9, 2025

Check the documentation preview:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Email service
8 participants